php - static properties and instances -


What if I create a square with property and two examples of this will be created ?

Will the stable property be shared between the two parties and will not be duplicated?

Yes, this is the definition of a property.

Static properties belong to class , not class examples .

class some class {private static $ example count = 0; Function __ conversion () {self :: $ instanceCount ++; // do other stuff} function example count () {return self :: $ instanceCount; }} $ One = new new class (); Resonate $ one- & gt; Example count (); // 1 $ two = new something (); Resonate $ one- & gt; Example count (); // 2 resonant $ two-> Example calculation (); // 2

Comments