Difference between revisions of "ObjectsAndRefs"

From Hashphp.org
Jump to: navigation, search
Line 12: Line 12:
  
 
     <tr><td colspan="2">
 
     <tr><td colspan="2">
         This code creates a new class, SimpleClass, with no properties or methods.
+
         The above code creates a new class, SimpleClass, with no properties or methods.
 
         It then creates a new instance of this class and binds it to the name '$instance'.
 
         It then creates a new instance of this class and binds it to the name '$instance'.
 
     </td></tr>
 
     </td></tr>

Revision as of 15:44, 26 July 2011

This page attempts to provide a visual guide to how objects - and references to them - work in PHP 5.0 and later.






class SimpleClass { }
$instance = new SimpleClass();
ObjRefImg0.png
       The above code creates a new class, SimpleClass, with no properties or methods.
       It then creates a new instance of this class and binds it to the name '$instance'.
$assigned = $instance; ObjRefImg1.png
Explain the code here
$instance->var = '$assigned will have this value as well'; ObjRefImg3.png
Explain the code here
$reference =& $instance; ObjRefImg2.png
Explain the code here
$instance = null; ObjRefImg4.png
Explain the code here