fork download
  1. <?php
  2.  
  3. class Test
  4. {
  5.  
  6. public $valor = 'testeClasse';
  7.  
  8. }
  9. //instância do objeto
  10. $objeto = new Test();
  11.  
  12. //array
  13. $array['valor'] = 'testeArray';
  14.  
  15. //cast array
  16. $saidaArray = (array) $objeto;
  17. //cast object
  18. $saidaObject = (object) $array;
  19.  
  20. //saídas
  21. print_r($saidaArray);
  22. print_r($saidaObject);
Success #stdin #stdout 0.01s 52472KB
stdin
Standard input is empty
stdout
Array
(
    [valor] => testeClasse
)
stdClass Object
(
    [valor] => testeArray
)