这似乎测试正常。我将属性更改为“公共”,这样我就可以避免编写另一个类。移动部件从第 80 行开始。
http://www.laprbass.com/RAY_temp_casper.php
<?php // RAY_temp_casper.php
error_reporting(E_ALL);
echo '<pre>';
/* STRUCTURE WE ARE TRYING TO CREATE
master_monitoring_collection Object (
[position:protected] => 0
[storage:protected] => Array (
[0] => master_monitoring Object (
[table:protected] => master_monitoring
[values:protected] => Array (
[prvd_name] => Axis
[prvd_status] => Y
[prvd_lastprob] =>
[prvd_prob] =>
[prvd_traffic_sms] =>
[update_date] => 2011-11-26 22:54:39 )
)
[1] => master_monitoring Object (
[table:protected] => master_monitoring
[values:protected]=> Array (
[prvd_name] => Esia
[prvd_status] => Y
[prvd_lastprob] =>
[prvd_prob] =>
[prvd_traffic_sms] =>
[update_date] => 2011-11-26 22:54:07
)
)
*/ // END OF STRUCTURE
Class Master_monitoring
{
public $table, $values;
public function __construct($values)
{
$this->table = 'master_monitoring';
$this->values = $values;
}
}
Class Master_monitoring_collection
{
public $position, $storage;
public function __construct($array)
{
$this->position = 0;
$this->storage = $array;
}
}
$a = array
( 'prvd_name' => 'Axis'
, 'prvd_status' => 'Y'
, 'prvd_lastprob' => NULL
, 'prvd_prob' => NULL
, 'prvd_traffic_sms' => NULL
, 'update_date' => '2011-11-26 22:54:39'
)
;
$b = array
( 'prvd_name' => 'Esia'
, 'prvd_status' => 'Y'
, 'prvd_lastprob' => NULL
, 'prvd_prob' => NULL
, 'prvd_traffic_sms' => NULL
, 'update_date' => '2011-11-26 22:54:07'
)
;
$aobj = new Master_Monitoring($a);
$bobj = new Master_Monitoring($b);
$mobj = array($aobj, $bobj);
$monitors = new Master_monitoring_collection($mobj);
// DOES IT LOOK RIGHT? (YES)
print_r($monitors);
// SHOW HOW TO USE THE ITERATOR
foreach ($monitors->storage as $mmo)
{
var_dump($mmo->values['prvd_name']);
}