Answer the question
In order to leave comments, you need to log in
Variable declaration in PHP
Answer received , thanks to everyone ... for the minuses in karma - especially :-\
I googled for a long time, but I didn’t find a clear answer - classes, OOP, etc. are everywhere :( I ask you, gentlemen:
What is the fundamental difference between:
function f() {
var $variable = 1;
... }
and
function f() {
$variable = 1;
... }
Answer the question
In order to leave comments, you need to log in
var does not exist in nature, it is from php4, it is not in the fifth. You should always use $foo = 'bar';
PHP is not JS. "var" is the old way of declaring class fields (now private, protected, public). And, by the way, it googles .
The first option is only suitable for classes
class bbb {
var $i=1;
}
although it is deprecated. This will not work in a
function function bbb() {
var $i=1;
}
will just give an error
. And the second option is only good for functions and "just code" if you define
class bbb {
var $i=1;
}
then it will throw an error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question