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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -