Re: [PHP] Object to array conversion oddity

This is a discussion on Re: [PHP] Object to array conversion oddity within the PHP General forums, part of the PHP Programming Forums category; Here's a more accurate example: <?php class Myclass { public $field1 = ''; private $field2 = ''; protected $field3 = ''; } $myclass = new Myclass; var_dump($...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-23-2006
Marcus Bointon
 
Posts: n/a
Default Re: [PHP] Object to array conversion oddity

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) ""
["field2:private"]=>
string(0) ""
["field3:protected"]=>
string(0) ""
}
array(3) {
["field1"]=>
string(0) ""
["Myclassfield2"]=>
string(0) ""
["*field3"]=>
string(0) ""
}

So it seems protected fields behave differently too.

Marcus
--
Marcus Bointon
Synchromedia Limited: Creators of http://www.smartmessages.net/
marcus@synchromedia.co.uk | http://www.synchromedia.co.uk/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:24 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0