Re: SimpleXML and the Single String (SOLVED)
| From: | Marco Behnke | Date: | Wed, 22 Feb 2012 20:31:34 +0000 |
| Subject: | Re: SimpleXML and the Single String (SOLVED) | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316761@lists.php.net to get a copy of this message | ||
Am 22.02.12 16:04, schrieb Jay Blanchard:
> On 2/22/2012 8:32 AM, marco@behnke.biz wrote:
>> There is another nice way.
>> You can pass a second value to the simple xml constructor which is a
>> class
>> name to be used instead of SimpleXMLElement.
>> You can write your own class that extends SimpleXMLElement and
>> override the
>> magic methods to skip the casting
>>
> I don't really see a need to add an extra layer or class extension
> when casting works fine. Am I wrong? Why add several lines of code in
> an extension class?
>
To keep the code readable?
$value = $xml->node;
vs.
$value = (String)$xml->node;
I like the first one. Plus you handle it to dynamically to the right type
function __get($value)
{
if is float return float casted value
if is boolean ...
and so on
}
--
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3
Tel.: 0174 / 9722336
e-Mail: marco@behnke.biz
Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal
http://www.behnke.biz
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc