note 126445 deleted from language.oop5.anonymous by salathe

From: Date: Tue, 21 Sep 2021 18:22:24 +0000
Subject: note 126445 deleted from language.oop5.anonymous by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216986@lists.php.net to get a copy of this message
Note Submitter: blue_1598 at yahoo dot com ---- Just a little observation. !!!! **** I've made a mistake in the OBSERVATION (1) explanation and i'll correct it here, right now! ** In the OBSERVATION (2) posted on this webpage/topic the behavior that I discovered and described it's ok explained so go to my previous message to see that strange behavior and run the code that I attached there . **** TOPIC: About the INNER CLASS that EXTEND the OUTHER CLASS:: **** ** OBSERVATION 1 CORRECTED: (The anonymous inner class access throught inheritance the visible members [public/protected] but don't modify anything because they aren't transmitted by reference what confused me before run my own tests). The anonymous inner class (that inherit the outer one) it's like a normal named class that it's a fully independent class that at instantiation automatically clone (copy throught assignement inner_prop = outer_prop) the values of old outer class Vvisible instance properties [public and protected] because of the inheritance mecanism ("INNER class extends OUTER class"). Also the visible [public/protected] methods of the outer class are inherited. :) It's like a normal class extend another class. In particular case I like to name an anonymous class : "DISPOSABLE CLASS "; intended to be used only for one unique instantiation! The only difference that apperas here is that the anonymous class hasn't a name and can be use only to instantiate 1 (one) object at a time. If u want another one must rewrite the class code again (and u want insted to create a normal class and instantiate any objects u need). P.S: The major difference that I suddenly discovered it's in case of the private members. I exposed that special behavior in my previous message at the " OBSERVATION (2) - here: " https://www.php.net/manual/en/language.oop5.anonymous.php#126442 " - go and check/search it on this webage). I think it's related to some old link created but not updated by the PHP engine for a inner variable of an self PHP engine created object so that the private property inside inherited but not overrided method points to an old container[type,value,is_ref,cnt_ref] structure (that PHP use to store and manipulate the data) and not the one of the current anonymous class object instance. Of course there are my speculation, I'm a PHP beginner programmer and I might be wrong! Also take care at this situation: If you don't extend the outer class ("INNER class extends OUTER class") even if the class is inside another method class (even inside magic methods) you will have just a simple anonymous class that behave like u code it yourself and it's shown in the first example of this manual. The first example of this manual (a sample anonymous class used to instantiate an object): <?php // Using an explicit class class Logger { public function log($msg) { echo $msg; } } $util->setLogger(new Logger()); // Using an anonymous class $util->setLogger(new class { public function log($msg) { echo $msg; } });

« previous php.notes (#216986) next »