Конвертация объекта PHP в массив и обратно

php конвертация объекта в массив

Как конвертировать объект в массив. PHP5

$item = array(    "color" => "black",    "size" => "medium",    "pieces" => 100,    "cost" => 44.99 );  $itemObject = (object) $item;  echo "Array as object:\n"; print_r($itemObject); echo "\n";  $itemArray = (array) $itemObject; echo "Object as array:\n"; print_r($itemArray);

вернет

Array as object: stdClass Object (    [color] => black    [size] => medium    [pieces] => 100    [cost] => 44.99 )  Object as array: Array (    [color] => black    [size] => medium    [pieces] => 100    [cost] => 44.99 )

а как будет работать с защищенными и приватными свойствами объекта?

class Casting {    public $pub = "I'm a public member";    protected $pro = "I'm a protected from outlanders";    private $pri = "I'm a hidden property"; }  $casting = new Casting();  print_r($casting); print_r((array) $casting);

Вернет

Casting Object (    [pub] => I'm a public member    [pro:protected] => I'm a protected from outlanders    [pri:private] => I'm a hidden property ) Array (    [pub] => I'm a public member    [*pro] => I'm a protected from outlanders    [Castingpri] => I'm a hidden property )