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.
The var keyword creates a property in a class. Since PHP 5, it is equivalent to the public keyword. Note: The var keyword is only used for compatibility reasons. Since PHP 5, the keywords private , protected and public should be used instead.
The var keyword is used to declare variables in JavaScript. Before you use a variable in a JavaScript program, you must declare it. Variables are declared with the var keyword as follows. Storing a value in a variable is called variable initialization.
A variable variable takes the value of a variable and treats that as the name of a variable. In the above example, hello, can be used as the name of a variable by using two dollar signs.
PHP $ and $$ Variables. The $var (single dollar) is a normal variable with the name var that stores any value like string, integer, float, etc. The $$var (double dollar) is a reference variable that stores the value of the $variable inside it.
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() { } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With