oop - How to extract variable from one function into another in same class in php -


i want use variable value 1 function function of same class. using abstract class using declaring variable global indirectly. can not declare variable global in class. demo code follows:

<?php  abstract class abc {    protected    $te; }  class test extends abc { public  function team() {     $te = 5;     $this->te += 100; }  public  function tee() {     $tee = 51;     return $this->te; }  } $obj = new test(); echo $obj->tee();   //echo test::tee(); ?> 

is possible can echo 105 answer there?

my main motive want learn how variable value 1 function using without declaring global in same class please let me know possible or need delete question ?

<?php  abstract class abc {    protected    $te; }  class test extends abc {     public function __construct() {         $this->te = 5;     }      public  function team()     {         $this->te += 100;     }      public  function tee()     {         return $this->te;     } }  $obj = new test(); $obj->team(); echo $obj->tee(); 

-- edit: make @ least use of abstract "feature":

<?php  abstract class abc {     protected    $te;      abstract public function team();     public  function tee()     {         return $this->te;     } }  class test extends abc {     public function __construct() {         $this->te = 5;     }      public function team()     {         $this->te += 100;     } }  $obj = new test(); $obj->team(); echo $obj->tee(); 

-- edi2: since you've asked whether must invoke team (and deleted comment):

<?php  abstract class abc {     protected    $te;      abstract public function team();     public  function tee()     {         $this->team();         return $this->te;     } }  class test extends abc {     public function __construct() {         $this->te = 5;     }      public function team()     {         $this->te += 100;     } }  $obj = new test(); echo $obj->tee(); 

so, yes, has invoked somewhere. depending on you're trying achieve there numerous ways so.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -