The Note You're Voting On
amolocaleb at gmail dot com ¶ 7 years ago
If an object is typecasted into an array and "extracted",only the public properties will be accessible.Methods are of course omitted.
<?php
class Test{
public $name = '';
protected $age = 10;
public $status = 'disabled';
private $isTrue = false;
public function __construct()
{
$this->name = 'Amolo';
$this->status = 'active';
}
public function getName()
{
return $this->name;
}
public function getAge()
{
return $this->age;
}
public function getStatus()
{
return $this->status;
}
}
$obj = (array) new Test();
var_dump($obj);
/* array(4) { ["name"]=> string(5) "Amolo" ["*age"]=> int(10) ["status"]=> string(6) "active" ["TestisTrue"]=> bool(false) } */
extract((array)new Test());
echo $name; //Amolo
echo $status; //active
echo $age;//Notice: Undefined variable: age
echo $isTrue;//Notice: Undefined variable: isTrue