oop - When do we return values in PHP functions? -


sorry question don't understand how works:

class person {     public static $age = 1;      public function havebirthday() {         static::$age +=1;     } }  $joe = new person; $joe->havebirthday();  echo person::$age; 

what i'm not understanding this:

public function havebirthday() {     static::$age +=1; } 

isn't supposed return $age otherwise value lost? why still working?

thanks!

you've defined static, means class level variables instead of instance level.

so when call $joe->havebirthday(); updates class level variable of person class can accessed using person::$age;.

static variables not need returned, can access directly class.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -