I am counting items that belong to each object in a class array. It appears to work, but when I enable error_reporting(E_ALL) to make sure, I get the following error:
Undefined property: aryTxns [in file on line nnn]
Class looks roughly like this:
Resource[]->aryTxns[]->property1 ...
Array of class objects looks like this:
$aryResources
The code to perform the count the transactions owned by each resource:
$intTotalTxns += count($aryResources[$intLoopCtr]->aryTxns);
Do we consider the use of array functions on class objects as operative, and force ourselves to ignore the warnings?
TIA
counting array items belonging to a class object - works?
Moderator: General Moderators
Code: Select all
<pre><?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
class Property
{
var $whatever;
function Property($x,$y)
{
$this->whatever = $x . '/' . $y;
}
}
class Txns
{
var $aryTxns = array();
function Txns($i)
{
for($j=0; $j!=$i; $j++)
$this->aryTxns[] = new Property($i, $j);
}
}
$aryResources = array();
for($i=0; $i!=10; $i++)
$aryResources[] = new Txns($i);
$count = 0;
for($i=0; $i!=count($aryResources); $i++)
{
$count += count($aryResources[$i]->aryTxns);
print_r($aryResources[$i]->aryTxns);
}
echo $count;
?></pre>