Casting an Array with Numeric Keys as an Object

后端 未结 4 1277
余生分开走
余生分开走 2020-11-27 07:23

I was poking around PHPs casting mechanism, and ran into an odd case when casting an array as an object

$o = (object) array(\'1\'=>\'/foo/bar\');   
$o =          


        
4条回答
  •  悲哀的现实
    2020-11-27 08:05

    It appears that the ArrayObject class can access the properties

    $a = new ArrayObject($obj);
    echo $a[0];
    

提交回复
热议问题