function - calling class object from other class Not using "global" php -
i new php please excuse lack of knowledge. using eclipse , have project 3 files inside project. creating find discount class takes class object call function class. error:
notice: undefined variable: getinfoclass line .. fatal error: call member function getage() on non-object line ...
i tried read cant seem understand it. please help. thanks
formresponse:
include "getinfo.php"; include "ifdiscount.php"; $ifdiscount= new ifdiscount(); echo $ifdiscount->finddiscount();
class ifdiscount:
class ifdiscount { public function finddiscount(){ $age = $getinfoclass->getage(); echo $age;}}
$getinfoclass
not available finddiscount()
because out of scope. should pass finddiscount()
parameter make available method:
public function finddiscount($getinfoclass){ $age = $getinfoclass->getage(); return $age; } echo $ifdiscount->finddiscount($getinfoclass);
(you want return $age
, not echo it. explicitly echo when call method.)
Comments
Post a Comment