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") {} Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
punk_runner Posted January 17, 2011 Author Share Posted January 17, 2011 Explain? Quote Link to comment 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 } } Quote Link to comment Share on other sites More sharing options...
punk_runner Posted January 17, 2011 Author Share Posted January 17, 2011 Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.