Benim nesneler tüm kendilerini bir JSON dize iade edebilmek için isterdim.
Yani) (bir AsJSON ile, yöntemi uzatmak benim tüm nesneler için bir temel sınıf oluşturuldu:
class BaseObject {
public function AsJSON()
{
$JSON=array();
foreach ($this as $key => $value)
{
if(is_null($value))
continue;
$JSON[$key] = $value;
}
return json_encode($JSON);
}
}
And then extend my child classes from that:
class Package extends BaseObject {
...
}
So in my code, I expect to do this:
$Box = new Package;
$Box->SetID('123');
$Box->SetName('12x8x6');
$Box->SetBoxX('12');
$Box->SetBoxY('8');
$Box->SetBoxZ('6');
echo $Box->AsJSON();
But the JSON string it returns only contains the BaseClass's properties, not the child properties.
$ Bu çocuğun özelliklerini ifade, değil ebeveynin böylece nasıl AsJSON () işlevini değiştirmek?