我有这样一个数组:
$array = Array ( 0 => 'oooo',
1 => 'no',
2 => 'mmmm',
3 => 'yes' );
Run Code Online (Sandbox Code Playgroud)
我想搜索"是"这个词.我知道array_search(),但我想匹配"是","是"和"是".
我怎样才能做到这一点?
所以我正在探索Reflection类的使用。我注意到一些事情。即使在 Origin 类中,也必须先设置属性的可访问性,然后才能使用属性的值或名称。
我想知道是否可以通过ReflectionClass. 例如
class MyClass
{
public $bathroom = 'Dirty';
protected $individual = 'President';
private $conversation = '****************';
function outputReflectedPublic()
{
$reflection = new ReflectionClass($this);
$props = $reflection->getProperties(ReflectionProperty::IS_PUBLIC);
foreach($props as $prop)
echo $prop->getName() . ' : ' . $prop->getValue($this);
}
}
$obj = new MyClass();
$obj->outputReflectedPublic();//bathroom : Dirty
//now we add a new property
$obj->$ect = 'ify';
$obj->outputReflectedPublic();//bathroom : Dirty //same as before
Run Code Online (Sandbox Code Playgroud)
现在我对此并不感到太惊讶。我试图查看该属性是否作为受保护/私有/静态位于实例中ReflectionProperty::IS_PRIVATE,并带有 ,ReflectionProperty::IS_PROTECTED和ReflectionProperty::IS_STATIC
我还用来$prop->setAccessible(true)防止无法访问的错误。我无法看到该$ect …