Re: [PHP] Object to array conversion oddity

2006-09-26 Thread Richard Lynch
On Sat, September 23, 2006 10:39 am, Marcus Bointon wrote: On 23 Sep 2006, at 16:37, Ray Hauge wrote: Could you do something like this? $private = Myclass $protected = *; No, because if I have a property called 'Myclassfield1', after casting to an array I can't tell if it's private

Re: [PHP] Object to array conversion oddity

2006-09-26 Thread Marcus Bointon
On 26 Sep 2006, at 23:52, Richard Lynch wrote: You start using that PHP5 private/protected stuff, and it just doesn't make sense to coerce it to an array, imho. I'm quite aware of that, and in this case I'm using it in a one-off string-and-glue fix for a specific problem until I fix it

Re: [PHP] Object to array conversion oddity

2006-09-24 Thread Marcus Bointon
On 24 Sep 2006, at 01:05, Robert Cummings wrote: Blah, blah, blah. The documentation is probably out of date and applied to PHP4. Feel free to get off your arse and volunteer if you don't like it :) You don't get have your cake and eat it *PTHTHTHTHTTHTHTH* How exactly am I not helping by

Re: [PHP] Object to array conversion oddity

2006-09-24 Thread Marcus Bointon
On 24 Sep 2006, at 01:09, Robert Cummings wrote: It's broken, it doesn't preserve references. ?php class A { private $A; } class B extends A { private $A; public $B; protected $c;} $a = new B; $b = new B; $b-B = $a; var_dump(object2array($b)); ? array(3) { [A]= NULL [B]= object(B)#1

Re: [PHP] Object to array conversion oddity

2006-09-24 Thread Robert Cummings
On Sun, 2006-09-24 at 10:53 +0100, Marcus Bointon wrote: On 24 Sep 2006, at 01:05, Robert Cummings wrote: Blah, blah, blah. The documentation is probably out of date and applied to PHP4. Feel free to get off your arse and volunteer if you don't like it :) You don't get have your

Re: [PHP] Object to array conversion oddity

2006-09-24 Thread Ray Hauge
On Sunday 24 September 2006 15:00, Robert Cummings wrote: Because you're pointing it out to the wrong people. See bugs.php.net. Maybe you missed it, but he did submit a bug report: http://bugs.php.net/?id=38935 He just wanted to see if other people had run into a similar situation before

Re: [PHP] Object to array conversion oddity

2006-09-24 Thread Marcus Bointon
On 24 Sep 2006, at 22:07, Ray Hauge wrote: Maybe you missed it, but he did submit a bug report: http://bugs.php.net/?id=38935 He just wanted to see if other people had run into a similar situation before submitting the bug... from my understanding. I don't want to put words in Marcus'

Re: [PHP] Object to array conversion oddity

2006-09-24 Thread Robert Cummings
On Sun, 2006-09-24 at 22:26 +0100, Marcus Bointon wrote: On 24 Sep 2006, at 22:07, Ray Hauge wrote: Maybe you missed it, but he did submit a bug report: http://bugs.php.net/?id=38935 He just wanted to see if other people had run into a similar situation before submitting the

[PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon
A simple class like this: class Myclass() { public $field1 = ''; private $field2 = ''; public function __sleep() { return array('field1', 'field2'); } } $myclass = new Myclass; If I var_dump this, I get: object(Myclass)#6 (2) { [field1]= string(0) [field2:private]= string(0) } If

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Ray Hauge
On Saturday 23 September 2006 09:40, Marcus Bointon wrote: A simple class like this: class Myclass() { public $field1 = ''; private $field2 = ''; public function __sleep() { return array('field1', 'field2'); } } $myclass = new Myclass; If I var_dump this, I get: object(Myclass)#6

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon
On 23 Sep 2006, at 15:51, Ray Hauge wrote: To me it looks like they append the name of the class to any private variables. I would guess that it does this to make sure you know what you're doing and using the private variable like that. I'm just guessing at that point though. Well, I

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon
Here's a more accurate example: ?php class Myclass { public $field1 = ''; private $field2 = ''; protected $field3 = ''; } $myclass = new Myclass; var_dump($myclass); var_dump((array)$myclass); ? This produces: object(Myclass)#1 (3) { [field1]= string(0)

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Ray Hauge
On Saturday 23 September 2006 10:04, Marcus Bointon wrote: On 23 Sep 2006, at 15:51, Ray Hauge wrote: To me it looks like they append the name of the class to any private variables. I would guess that it does this to make sure you know what you're doing and using the private variable

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon
On 23 Sep 2006, at 16:37, Ray Hauge wrote: Could you do something like this? $private = Myclass $protected = *; No, because if I have a property called 'Myclassfield1', after casting to an array I can't tell if it's private property called 'field1' or a public property called

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Robert Cummings
On Sat, 2006-09-23 at 16:04 +0100, Marcus Bointon wrote: On 23 Sep 2006, at 15:51, Ray Hauge wrote: To me it looks like they append the name of the class to any private variables. I would guess that it does this to make sure you know what you're doing and using the private variable

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Robert Cummings
On Sat, 2006-09-23 at 11:46 -0400, Robert Cummings wrote: On Sat, 2006-09-23 at 16:04 +0100, Marcus Bointon wrote: On 23 Sep 2006, at 15:51, Ray Hauge wrote: To me it looks like they append the name of the class to any private variables. I would guess that it does this to make sure

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon
On 23 Sep 2006, at 16:46, Robert Cummings wrote: And the likelihood of you having a property called Myclassfield1 is? Sure, but don't you think that coding should at least try to be driven by logic rather than luck? I'm also not denying that it's not too hard to work around (with a

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Ray Hauge
On Saturday 23 September 2006 11:41, Marcus Bointon wrote: On 23 Sep 2006, at 16:46, Robert Cummings wrote: And the likelihood of you having a property called Myclassfield1 is? Sure, but don't you think that coding should at least try to be driven by logic rather than luck? I'm also not

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Jon Anderson
Marcus Bointon wrote: Sure, but don't you think that coding should at least try to be driven by logic rather than luck? I'm also not denying that it's not too hard to work around (with a function not dissimilar to what you suggested), but I'd really prefer it if it just did what it says on the

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon
On 23 Sep 2006, at 18:54, Jon Anderson wrote: If you just want an array of properties, add this to your class... That's exactly the kind of thing I was on about. Since reflection gives access to all this information, why bother trying to squeeze the same info into an array-shaped

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Marcus Bointon
I've written a function that does a conversion that matches the docs, based on the other info I've mentioned: /** * Clean up the name munging that PHP applies while casting from object to array * The resulting array looks like what the documentation says that (array)$object delivers, but

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Robert Cummings
On Sat, 2006-09-23 at 17:41 +0100, Marcus Bointon wrote: On 23 Sep 2006, at 16:46, Robert Cummings wrote: And the likelihood of you having a property called Myclassfield1 is? Sure, but don't you think that coding should at least try to be driven by logic rather than luck? I'm also not

Re: [PHP] Object to array conversion oddity

2006-09-23 Thread Robert Cummings
On Sat, 2006-09-23 at 22:35 +0100, Marcus Bointon wrote: I've written a function that does a conversion that matches the docs, based on the other info I've mentioned: /** * Clean up the name munging that PHP applies while casting from object to array * The resulting array looks like