This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
why am I getting these errors?
Undefined variable: num1
Cannot access empty property
class sum{
public $num1=1;
public function fun($num2){
return $this->$num1+$num2;
}
}
$number = new sum();
echo $number->fun(3);
class sum{
public $num1=1;
public function fun($num2){
return $this->num1+$num2;
//removed $^^
}
}
$number = new sum();
echo $number->fun(3);
Related
This question already has answers here:
How do I correct this Illegal String Offset?
(4 answers)
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 12 months ago.
I have Illegal String Offset Error
This is my code
function _feature_faq($param) {
$html = '';
$html_wrapper='';
$row = 1;
$is_faq=false;
$feature_faq = $param['feature']; // <---
if(empty($feature_faq)):
$feature_faq = 'none';
endif;
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Using LIKE in bindParam for a MySQL PDO Query [duplicate]
(2 answers)
Closed 3 years ago.
Why isn't this working? I've viewed the past posts on the subject and nothing worked for me.
$sql_strongsdef_ses = "SELECT id, strongs, etym_strongs FROM ".$tablename." WHERE etym_strongs LIKE ?";
$params = array("'%".$getSearchEtymStrongs."%'");
$result_strongsdef_ses = $conn->prepare($sql_strongsdef_ses);
$result_strongsdef_ses->execute($params);
echo "<span style=\"color: red;\">".$sql_strongsdef_ses."</span><br /><br />\n";
//while ($row_ses = $result_strongsdef_ses->fetch()){
while($row_ses = $result_strongsdef_ses->fetch(PDO::FETCH_ASSOC)){
$id_ses = $row_ses['id'];
$strongs_ses = $row_ses['strongs'];
$etymstrongs_ses = $row_ses['etym_strongs'];
}
var_dump($strongs_ses);
I get the error:
Notice: Undefined variable: strongs_ses in \edit.php on line 52
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 4 years ago.
I'm getting an undefined offset error
<?php
function ara($one, $two, $three)
{
#preg_match_all('/' . preg_quote($one, '/') .
'(.*?)'. preg_quote($two, '/').'/i', $three, $m);
return #$m[1];
}
$link = "example.com";
$article = file_get_contents($link);
$sport = ara('data-bin="','"',$article);
$channel = ara('data-videobin="','"',$article);
for ($i=0;$i<50;$i++)
echo"<span class='linko'><a target='_blank' href='example.org/live1.php?id=".($channel[$i]."'>$sport[$i]</a>"."<br></span>"); // error is here
?>
How can I fix it? I'am waiting for your helps. Thanks.
These codes are for a live channel website.
The channel variable has less than 50 elements.
Usually in a loop, you should set the end condition to the size of the array.
for ($i=0;$i<sizeof($channel);$i++)
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 5 years ago.
What am I doing wrong?
I have a error about a undefined variable but it is defined or not?
Undefined variable: url in /mnt/web121/d2/33/58167933/htdocs/includes/functions.php on line 74
$url = "http://www.crime-world.eu";
function logincheck(){
if (empty($_SESSION['username'])){
check_legit($url);
echo "<SCRIPT LANGUAGE='JavaScript'>window.location='index.php';</script>";
exit();
}
check_legit($url);
}
$url is a global variable. Declare it as global in your function.
function logincheck(){
global $url;
...
}
$url is not in the function checklogin scope, you can pase it to the function with function parameter or use it as a global variable.
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 7 years ago.
I'm in a ambiguous situation.
Here's the concerned code:
http://prntscr.com/9edm4j
public function verifyReply($reponse)
{
$qr = $this->mStopBOT;
if(isset($_SESSION["stopBOT"]))
{
if($_SESSION["stopBot"] === false)
{
$_SESSION["stopBOT"] = true;
if($qr[$_SESSION["stopBOTq"]][1] == $reponse)
return true;
}
}
return false;
}
And here is the problem:
http://prntscr.com/9ednwm
PHP Notice: Undefined index: stopBot in /home/*************/public_html/inc/classes/Security.inc.php on line 92
The isset() function returns true, but when I use the function, it says that the index is undefined! ?
Regards and Thanks in Advance
You are checking if $_SESSION['stopBOT'] is set but then use $_SESSION['stopBot']
Note the case difference, stopBOT vs stopBot