note 75909 deleted from language.oop5.typehinting by felipe

From: Date: Sat, 15 Dec 2007 01:23:32 +0000
Subject: note 75909 deleted from language.oop5.typehinting by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133492@lists.php.net to get a copy of this message
Note Submitter: yarco dot w at gmail dot com ---- I think php could add this feature: user could self define the __toXXX magic method. So when there exists type hinting, the object could automatically be changed into such type. Code like this: <?php class A { public function __toArray() { // do change to array } } function insertData(array $array) { // insert data into database } insertData($a = new A()); ?> object $a could automatically call __toArray(). It is very useful when you change data from database into model under MVC enviroment.(For example, zend framework. So you could do $table->insert($a); no need: $table->insert($a->toArray()); //such ugly code if insert defined as insert(array $array);

« previous php.notes (#133492) next »