note 75909 added to language.oop5.typehinting

From: Date: Thu, 21 Jun 2007 08:33:35 +0000
Subject: note 75909 added to language.oop5.typehinting
Groups: php.notes 
Request: Send a blank email to php-notes+get-127851@lists.php.net to get a copy of this message
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); ---- Server IP: 222.73.207.140 Probable Submitter: 61.173.109.21 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.typehinting.php Edit -- https://master.php.net/note/edit/75909 Del: integrated -- https://master.php.net/note/delete/75909/integrated Del: useless -- https://master.php.net/note/delete/75909/useless Del: bad code -- https://master.php.net/note/delete/75909/bad+code Del: spam -- https://master.php.net/note/delete/75909/spam Del: non-english -- https://master.php.net/note/delete/75909/non-english Del: in docs -- https://master.php.net/note/delete/75909/in+docs Del: other reasons-- https://master.php.net/note/delete/75909 Reject -- https://master.php.net/note/reject/75909 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127851) next »