<?php
class UserModel
{
protected const DEFAULT_ALLOWED_FIELDS = [
'username',
'status',
'status_message',
'active',
'last_active',
'deleted_at',
];
// ... other properties
protected $allowedFields = self::DEFAULT_ALLOWED_FIELDS;
// ... other properties
}
class MyModel extends UserModel
{
protected $allowedFields = [
...self::DEFAULT_ALLOWED_FIELDS,
'phone_number',
'tax_id',
];
}
$model = new MyModel();
$property = new ReflectionProperty($model, 'allowedFields');
$property->setAccessible(true);
var_dump($property->getValue($model));
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- array(8) {
[0]=>
string(8) "username"
[1]=>
string(6) "status"
[2]=>
string(14) "status_message"
[3]=>
string(6) "active"
[4]=>
string(11) "last_active"
[5]=>
string(10) "deleted_at"
[6]=>
string(12) "phone_number"
[7]=>
string(6) "tax_id"
}
preferences:
111.93 ms | 407 KiB | 5 Q