What is the difference between an object variable and a class variable? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

What is the difference between an object variable and a class variable?

I can't tell the difference between the two in PHP language, I would like to understand how we declare an object variable and where we place them in a program in general.

20th Jan 2020, 5:32 AM
Hegel Motokoua
Hegel Motokoua - avatar
1 Resposta
+ 2
A variable which is not object dependent and is created only once per class and whose memory is shared by all the objects of the class is called a class variable. For eg- static variables in Java. A variable which is object dependent and is created every time a new object is created is called an object variable. In this example you can see that only one copy of "x" is created which is updated every time you change its value because it is a class variable. https://code.sololearn.com/c0QPGa6lLf3E/?ref=app
20th Jan 2020, 6:51 AM
Avinesh
Avinesh - avatar