How do I get an array of all the properties of the current class, excluding inherited properties?
You can reach it only with reflection, here suitable example:
<?php
class foo
{
protected $propery1;
}
class boo extends foo
{
private $propery2;
protected $propery3;
public $propery4;
}
$reflect = new ReflectionClass('boo');
$props = $reflect->getProperties();
$ownProps = [];
foreach ($props as $prop) {
if ($prop->class === 'boo') {
$ownProps[] = $prop->getName();
}
}
var_export($ownProps);
Result:
array (
0 => 'propery2',
1 => 'propery3',
2 => 'propery4',
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With