note 120798 added to language.types.array

From: Date: Mon, 13 Mar 2017 15:23:41 +0000
Subject: note 120798 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-208904@lists.php.net to get a copy of this message
Doc: If an object is converted to an array, the result is an array whose elements are the object's properties. The keys are the member variable names, with a few notable exceptions: integer properties are unaccessible. From what I understand, if a class property is an integer as value, it will not appear in array converted, BUT: php7.1.2 class PropertyObject { public $publicProperty = "public property object"; } class Admin { private $noValuePrivate; private $private = 'private attribute'; protected $protectedNoName; protected $protected = 'protected variable'; public $int = 4; public $public = 'public attribute'; public $noValuePublic; public $publicPropertyObject; public function __construct() { $this->publicPropertyObject = new PropertyObject(); } } $a = new Admin(); var_dump((array) $a); ----------------------------------------- array(8) { '\0Admin\0noValuePrivate' => NULL '\0Admin\0private' => string(17) "private attribute" '\0*\0protectedNoName' => NULL '\0*\0protected' => string(18) "protected variable" 'int' => int(4) 'public' => string(16) "public attribute" 'noValuePublic' => NULL 'publicPropertyObject' => class PropertyObject#2 (1) { public $publicProperty => string(22) "public property object" } } ---- Server IP: 72.52.91.14 Probable Submitter: 82.76.7.22 ---- Manual Page -- http://php.net/manual/en/language.types.array.php Edit -- https://master.php.net/note/edit/120798 Del: integrated -- https://master.php.net/note/delete/120798/integrated Del: useless -- https://master.php.net/note/delete/120798/useless Del: bad code -- https://master.php.net/note/delete/120798/bad+code Del: spam -- https://master.php.net/note/delete/120798/spam Del: non-english -- https://master.php.net/note/delete/120798/non-english Del: in docs -- https://master.php.net/note/delete/120798/in+docs Del: other reasons-- https://master.php.net/note/delete/120798 Reject -- https://master.php.net/note/reject/120798 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#208904) next »