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

cron - how to properly run Python script with crontab on every system startup -

elasticsearch - Is the order of operations guaranteed in a bulk update? -

Slow performance first queries on SQL Azure -