I met a problem when Call to a member function combinestring() on a non-object.
**Index.php**
inlcude("string.php");
calldata('usa');
**string.php**
$a=new a();
funciton calldata($val){
$st1="select a from table 1 where country=".$a->combinestring($val);
return $st1;
}
**Class A**
function combinestring($abc){
Return "'".$abc."'";
}
Unknow $a->combinestring($val);
How to solve this problem.
Best Regards
You’re getting error
because you are calling a member function on the variable that is not an object. That means
$ais not an object.In string.php , you cannot use
$ainside function definition because variable has local scope. You cannot access that object instance like that. You can however do this by using global variable.Your
string.phpfile should be like this:Head to this link for more information on variable scope: http://php.net/manual/en/language.variables.scope.php