Re: Casting objects.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2010/1/18 Shawn McKenzie <nospam@xxxxxxxxxxxxx>:
> Shawn McKenzie wrote:
>>>
>> 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
>
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.


-- 
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux