+ 1
what is main different between variable & object in php language
2 Réponses
+ 5
Considering PHP is a loose-typed language a variable in PHP can contain anything from numbers, strings, arrays, objects etc.
A variable is a block of memory filled with data, how the data is interpreted or treated, as number, string, array, or object is the task of the PHP engine. A variable, as its name implies, may alter its content throughout the script execution period, it's value is not persistent.
An object is an instance of its defining class, it's like the real thing opposed to its class which is imaginary, a class can be pictured as your imagination or idea of something, object is a reality form of that imagination or idea.
e.g. Imagine a car; you know it has 4 wheels, carries at least 2 passengers, has relative sized luggage etc. that is your car class. But you cannot use or drive an idea, you need a real thing, so you create a car based on your idea (class) of car, and the real car that you can drive is an object.
Hth, cmiiw
+ 3
A variable asoceatea an identfier and value. Objects are a collection of variables and methods/functions associated to a concept.
So a person object can contain multiple variables with information about that person.