WHAT is being copied and passed, however, is the pointer. "But objects are passed by reference!" A common misconception both here and in the Java world. Passing a variable to a function is done by default as a value pass, ie, you are working with a copy. (I haven't delved TOO deeply into the Zend engine yet, but as far as I can see, this applies)Ģnd principle, and source of the most confusion: Any time an object is assigned, a pointer is generated. (Using >= 5.3)Ī pointer stores a memory address to access an object. Hayley's code, for example, is doing EXACTLY what you should expect it should. The behavior in some of the "comprehensive" examples already posted can be explained in simpler unifying terms. The distinction between pointers and references is not particularly helpful. Unset( $a ) // Foo object 2 is still pointed to $c $a = NULL // Foo object 2 can be garbage collected now because $a and $c are now a reference to the same NULL value $a = & $c // Foo object 2 has 1 pointers pointing to it only, that pointer has 2 references: $a and $c Unset( $a ) // Foo object 2 is still pointed by $c $c = $a // $c and $a are pointers pointing to Foo object 2 Unset( $c ) // Foo object 1 can be garbage collected now. $a = clone $c // $a is now a pointer to Foo object 2, $c remains a pointer to Foo object 1 Unset( $b ) // $b no longer exists and $a is now NULL Foo object 0 can be garbage collected now $a = NULL // $a and $b now become a reference to NULL. $a = & $b // $a and $b are now references of a pointer pointing to Foo object 0 Unset( $a ) // A reference with reference count 1 is automatically converted back to a value. $a = new Foo // $a and $c are now references of a pointer pointing to Foo object 1, $b is still a pointer pointing to Foo object 0 $c = & $a // $c and $a are now references of a pointer pointing to Foo object 0 $b = $a // $b is a pointer pointing to Foo object 0, however, $b is a copy of $a $a = new Foo // $a is a pointer pointing to Foo object 0 Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting User Submitted Data Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts ? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto searchĪ reference is not a pointer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |