punk_runner Posted January 17, 2011 Share Posted January 17, 2011 What is the difference between declaring values at the top of a class versus in between the parenthesis of a method? Class MyClass { private $table = 0; public $field = "name"; // etc... Class MyClass { private $_table; public $field; public function myFunction($_table=0, $field="name") {} Link to comment https://forums.phpfreaks.com/topic/224754-decalring-vars-default-values/ Share on other sites More sharing options...
guyfromfl Posted January 17, 2011 Share Posted January 17, 2011 Scope *** oops sorry about that didn't mean to submit just that...here's the rest When you declare the variables at the top of the class you are preparing them to be used anywhere in the class. In the function declaration you are setting them as if they were local variables being passed for that function. Link to comment https://forums.phpfreaks.com/topic/224754-decalring-vars-default-values/#findComment-1160933 Share on other sites More sharing options...
punk_runner Posted January 17, 2011 Author Share Posted January 17, 2011 Explain? Link to comment https://forums.phpfreaks.com/topic/224754-decalring-vars-default-values/#findComment-1160934 Share on other sites More sharing options...
AbraCadaver Posted January 17, 2011 Share Posted January 17, 2011 Class MyClass { private $_table = 1; public $field = "name"; public function myFunction($_table=0) { echo $_table; // 0 echo $this->_table; // 1 echo $field; // echo $this->field; // name } } Link to comment https://forums.phpfreaks.com/topic/224754-decalring-vars-default-values/#findComment-1160963 Share on other sites More sharing options...
punk_runner Posted January 17, 2011 Author Share Posted January 17, 2011 Thanks. Link to comment https://forums.phpfreaks.com/topic/224754-decalring-vars-default-values/#findComment-1161048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.