类与in_array

test.php
<?php

class test{

private $name;
private $pas = 'ddd';
private $name1 = true;

function __construct($array1=array()){

foreach ($array1 as $key=>$value){

if(!in_array($key,array_keys(get_class_vars(get_class($this))))){
continue;
}

$this->setOption($key,$value);
}

}

private function setOption($key,$value){
$this->$key = $value;
}


}

?>
index.php
<?php

require 'test.php';
$object = new test(array('name'=>'xuepeng11'));

var_dump($object);


?>

你可能感兴趣的:(PHP)