Monday, August 5, 2019

What does PHP keyword 'var' do?



This is probably a very trivial question, but I haven't been able to find the answer neither through web search engines, nor on php.net. Please just direct me to where I can read about this, if you haven't got time to explain.





  1. What does the 'var' keyword mean in PHP?

  2. Are there any differences between PHP4 and PHP5?


Answer



It's for declaring class member variables in PHP4, and is no longer needed. It will work in PHP5, but will raise an E_STRICT warning in PHP from version 5.0.0 up to version 5.1.2, as of when it was deprecated. Since PHP 5.3, var has been un-deprecated and is a synonym for 'public'.



Example usage:



class foo {

var $x = 'y'; // or you can use public like...
public $x = 'y'; //this is also a class member variables.
function bar() {
}
}

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...