<?php
class myclass {
private $thevalue;
private $theword;
public function __construct (){
$num_args = func_num_args();
if($num_args > 0){
$args = func_get_args();
$this->theword = $args[0];
}
}
public function setvalue ($newvalue){
$this->thevalue = $newvalue;
}
public function getvalue () {
return $this->thevalue;
}
public function getword () {
return $this->theword;
}
}
$myclass1 = new myclass ("A");
$myclass1->setvalue (1);
$myclass2 = new myclass ("B");
$myclass2->setvalue (2);
$myclass3 = new myclass ("C");
$myclass3->setvalue (3);
$myclass4 = new myclass ("D");
$myclass4->setvalue (4);
$classarr = array ($myclass1,$myclass2,$myclass3,$myclass4);
function &findclass ($whichclass,$classarr){
for ($i = 0; $i < count ($classarr); $i++){
if ($classarr[$i]->getvalue() == $whichclass){
return $classarr[$i];
}
}
}
$myobject = new myclass ("");
$myobject =& findclass (3,$classarr);
echo $myobject->getword();
?>
|