Re: Casting objects.
| From: | Carlos Medina | Date: | Tue, 19 Jan 2010 21:45:11 +0000 |
| Subject: | Re: Casting objects. | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-301229@lists.php.net to get a copy of this message | ||
Richard Quadling schrieb:
2010/1/18 Shawn McKenzie <nospam@mckenzies.net>:i think it will be important since more PHP Developer are using Design Patterns. I think the cast functionality should be implemented once... Regards CarlosShawn McKenzie wrote:That's an interesting approach. Though I'm going to use reflection. I realise I need to hold some of the data in strings where the data is not a string (datetimes for example). So, using a docblock with a customtag and this seems to be working just fine. Extended ReflectionClass and ReflectionProperty. Thanks, Richard. Hi,Never mind, that was stupid. I saw that somewhere before, but obviously it doesn't work.I found some code, maybe I redeem myself? static public function cast(&$object, $class=__CLASS__){if(class_exists($class)) { $object = unserialize( preg_replace('/^O:[0-9]+:"[^"]+":/i', 'O:'.strlen($class).':"'.$class.'":', serialize($object))); }} $row = odbc_fetch_object($result); structuresRemovalReason::cast($row); -- Thanks! -Shawn http://www.spidean.com