PHP return reference (method name prefix &) and local static variable (static) read manual first
============
To return a reference from a function, you must use the reference operator when declaring the function and assigning the return value to a variable &:
Example 17-13. a reference is returned by the function.
For more information about references, see references.
Let's take a look at a lot of examples of registration modes that open-source code prefers.
Class a {} class B {} function & aa ($ name) {static $ class = array (); // The local static variable does not disappear with the execution of the method, but ends the lifecycle until the end of the entire source program. if (! $ Class [$ name]) // so the declaration/initialization statement here only takes effect at the first declaration {// and then calls this method, static variables no longer reinitialize value $ class [$ name] = new $ name ();} return $ class [$ name] ;}$ a = & aa ('A '); $ B = & aa ('B'); $ a2 = & aa ('A'); $ b2 = & aa ('B '); echo $ a ===$ a2? '$ A and $ a2 are the same instantiated objects.
': ''; Echo $ B ===$ b2? '$ B and $ b2 are the same instantiated objects ':'';