Declaring a variable in PHP

The response is received, thank you all... for the cons in karma — especially :-\

Long googled, but a clear answer is not found everywhere — classes, OOP, etc :( I Ask you, gentlemen:

What is the fundamental difference between:

function f() {
var $variable = 1;
... }

and
function f() {
$variable = 1;
... }
October 8th 19 at 03:14
5 answers
October 8th 19 at 03:16
Solution
var does not exist in nature, it is of пхп4, in the fifth it is not. You should always use $foo = 'bar';
Thank you - jed42 commented on October 8th 19 at 03:19
By the way, in PHP5 you can use the var was always, but to 5.1.3 error E_STRICT. And then stopped: ) - constance.Bei commented on October 8th 19 at 03:22
October 8th 19 at 03:18
PHP is not JS. "var" is the old way to declare class fields (now you should use private, protected, public). And, by the way, it's Google.
That's what I googled :) - jed42 commented on October 8th 19 at 03:21
October 8th 19 at 03:20
The first option is only good for classes
class bbb {
var $i=1;
}
although it is outdated. In the function it will not work
function bbb() {
var $i=1;
}
will give an error

And the second option is only good for functions and "just code", if You define
class bbb {
var $i=1;
}
it will give an error.
if You define
class bbb {
var $i=1;
}
it will give an error
Where is it? - jed42 commented on October 8th 19 at 03:23
What kind of artistic quoting?:)
The original was
The first option is only good for classes
class bbb {
var $i=1;
}
although it is outdated
- constance.Bei commented on October 8th 19 at 03:26
What kind of artistic quoting?:)
No arts :) habrastorage.org/storage2/b23/ee1/ceb/b23ee1ceba758e327536f2a6c0c466e8.png - jed42 commented on October 8th 19 at 03:29
Amazing. Can't believe my eyes, but You are right:) But I reread the message several times. Of course in the second case, var must not be present. Thank you. - kavon.Murphy commented on October 8th 19 at 03:32
October 8th 19 at 03:22
That the first option — Parse error?
PHP5.3, at least.
October 8th 19 at 03:24
I told you... no classes! :(
So You said — no classes var is not used? Or You do not read the answers? - jed42 commented on October 8th 19 at 03:27
Dear cons! The answer is "classes" have with Google. - constance.Bei commented on October 8th 19 at 03:30
and you are not satisfied because... (continue the phrase) - jed42 commented on October 8th 19 at 03:33
Because that's not what I need.

A comprehensive answer gave lashtal below. Thank you. - kavon.Murphy commented on October 8th 19 at 03:36

Find more questions by tags PHP