Best method of defining a public class variable in PHP -


is there difference between these methods of declaring , setting public class variable? there reason why choose 1 on other?

method 1

class example {    public $myarray;    function __construct() {     $this->myarray = array(1, 2, 3);   }    function showvar() {     print_r( $this->myarray );   }  } 

method 2

class example {    public $myarray = array(1, 2, 3);    function showvar() {     print_r( $this->myarray );   }  } 

in first case code evaluated each time create new class instance.

in second case - evaluated once when class parsed.

that's all.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -