Hi

Why there is a var function when we create classes??

I tried to use a variable with out type var before it and it worked

Recommended Answers

The "var" prefix was used in PHP 4. In PHP 5, you don't need to use the word "var" to declare a variable. In PHP 5, however, a warning will be generated if error handling is set to E_STRICT.

Jump to Post
In PHP 5, however, a warning will be generated if error handling is set to E_STRICT.

I think he answered your question before you asked it.

Declaring 'variable' properties with var in classes is good practice. Can't understand why you wouldn't want to.

Jump to Post

All 5 Replies

The "var" prefix was used in PHP 4. In PHP 5, you don't need to use the word "var" to declare a variable. In PHP 5, however, a warning will be generated if error handling is set to E_STRICT.

So does that means that it will be a problem if we dont declare it.

Member Avatar
In PHP 5, however, a warning will be generated if error handling is set to E_STRICT.

I think he answered your question before you asked it.

Declaring 'variable' properties with var in classes is good practice. Can't understand why you wouldn't want to.

Is VAR a function in PHP??
Is it used in a place other than the classes??

Member Avatar

var is used to declare a variable property within a class.
I haven't seen them used for php anywhere else.
It's certainly NOT a function AFAIK.
var or similar (e.g. 'dim') is used to declare variables in many languages, but procedural php doesn't require this keyword.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.