Re: [PHP] SimpleXML and the Single String (SOLVED)

2012-02-22 Thread Jay Blanchard
>> 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
> }

The code is no less readable my way, YMMV

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



Re: [PHP] SimpleXML and the Single String (SOLVED)

2012-02-22 Thread Marco Behnke
Am 22.02.12 16:04, schrieb Jay Blanchard:
> On 2/22/2012 8:32 AM, ma...@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: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz




signature.asc
Description: OpenPGP digital signature


Re: [PHP] SimpleXML and the Single String (SOLVED)

2012-02-22 Thread Jay Blanchard

On 2/22/2012 8:32 AM, ma...@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?


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



Re: [PHP] SimpleXML and the Single String (SOLVED)

2012-02-22 Thread ma...@behnke.biz
 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


Simon Schick  hat am 22. Februar 2012 um 00:16
geschrieben:

> Hi, Jay
>
> If you're not using the variable *$xmlCompany* somewhere else I'd try to
> skip the array and just do it with this single line:
> *$arrayLead[0]->Company = (string)
> $xml->SignonRq->SignonTransport->CustId->SPName;*
>
> The result should not differ from what you have now.
>
> Bye
> Simon
>
> 2012/2/21 Jay Blanchard 
>
> > Howdy,
> >
> > My PHP chops are a little rough around the edges so I know that I am
> > missing something. I am working with SimpleXML to retrieve values from
an
> > XML file like this -
> >
> > $xmlCompany = $xml->SignonRq->SignonTransport->CustId->SPName;
> >
> > If I echo $xmlCompany I get the proper information.
> >
> > If I use $xmlCompany as an array value though, I get this object -
> >
> > $arrayLead[0]->Company = $xmlCompany; // what I did
> > [Company] => SimpleXMLElement Object // what I got
> >(
> >[0] => Dadgummit
> >)
> > I tried casting AND THEN AS I TYPED THIS I figured it out...
> >
> > $xmlCompany = array((string)
> > $xml->SignonRq->SignonTransport->CustId->SPName); // becomes an array
> > $arrayLead[0]->Company = $xmlCompany[0]; // gets the right bit of the
array
> >
> > and the result is
> >
> >  [Company] => Dadgummit
> > Thanks for bearing with me!
> >
> >
> >
> >
> >
Marco Behnke
Dipl. Informatiker (FH), SAE Audio Engineer Diploma
Zend Certified Engineer PHP 5.3

Tel.: 0174 / 9722336
e-Mail: ma...@behnke.biz

Softwaretechnik Behnke
Heinrich-Heine-Str. 7D
21218 Seevetal

http://www.behnke.biz

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



Re: [PHP] SimpleXML and the Single String (SOLVED)

2012-02-21 Thread Simon Schick
Hi, Jay

If you're not using the variable *$xmlCompany* somewhere else I'd try to
skip the array and just do it with this single line:
*$arrayLead[0]->Company = (string)
$xml->SignonRq->SignonTransport->CustId->SPName;*

The result should not differ from what you have now.

Bye
Simon

2012/2/21 Jay Blanchard 

> Howdy,
>
> My PHP chops are a little rough around the edges so I know that I am
> missing something. I am working with SimpleXML to retrieve values from an
> XML file like this -
>
> $xmlCompany = $xml->SignonRq->SignonTransport->CustId->SPName;
>
> If I echo $xmlCompany I get the proper information.
>
> If I use $xmlCompany as an array value though, I get this object -
>
> $arrayLead[0]->Company = $xmlCompany; // what I did
> [Company] => SimpleXMLElement Object // what I got
>(
>[0] => Dadgummit
>)
> I tried casting AND THEN AS I TYPED THIS I figured it out...
>
> $xmlCompany = array((string)
> $xml->SignonRq->SignonTransport->CustId->SPName); // becomes an array
> $arrayLead[0]->Company = $xmlCompany[0]; // gets the right bit of the array
>
> and the result is
>
>  [Company] => Dadgummit
> Thanks for bearing with me!
>
>
>
>
>