A
A
Arris2012-02-18 16:41:54
PHP
Arris, 2012-02-18 16:41:54

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

5 answer(s)
L
lashtal, 2012-02-18
@Arris

var does not exist in nature, it is from php4, it is not in the fifth. You should always use $foo = 'bar';

S
Stdit, 2012-02-18
@Stdit

PHP is not JS. "var" is the old way of declaring class fields (now private, protected, public). And, by the way, it googles .

E
edogs, 2012-02-18
@edogs

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.

M
Melkij, 2012-02-18
@melkij

That the first option is Parse error?
PHP5.3 at least.

A
Arris, 2012-02-18
@Arris

I asked ... without classes! :(

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question