views:

94

answers:

3

is_array($src2->crit) is generating an "Undefined property: stdClass::$crit" error.

The line throwing the error is: if(is_array($src2->crit) && count($src->crit) > 0){

$src2->crit is initialized here.

$src2->crit = array();
 $src2->crit[0] = new dataSet();
 $src2->crit[0]->tblName = $tbl2;
 $src2->crit[0]->colName = "ID";
 $src2->crit[0]->val = $elm->editID;

When testing $src2->crit with this code.

print("\$src->crit is a ".$src->crit."<br />");
print_r($src->crit); print("<br />");

This is returned.

$src2->crit is a Array
Array ( [0] => dataSet Object ( [tblName] => sExam [colName] => ID [val] => 10 ) )

What am I not seeing/understanding correctly? If print("\$src2->crit is a ".$src->crit."<br />") returns that it is an array then why is is_array($src2->$crit) generating an error?

A: 

Can't reproduce:

<?php
$src2 = new stdClass();
$src2->crit = array();
$src2->crit[0] = new stdClass();
$src2->crit[0]->tblName = "whatever";
$src2->crit[0]->colName = "ID";
$src2->crit[0]->val = "value";
var_dump(is_array($src2->crit));

gives bool(true).

Artefacto
I'll check to see if something else is throwing it off
Brook Julias
A: 

It appears your biggest issue (according to the info you posted in the question) is that you refencing a different varaible name?

$elm->crit
$src->crit
Lizard
elm is the class which is being assigned to the src variable.
Brook Julias
We will need more code posted then, what you have posted doesn't make sense
Lizard
A: 

print("\$src2->crit is a ".$src->crit."<br />")

is_array($src2->$crit)

One of these things is not like the other!

One's referencing the crit property of the $src2 object.

The other is referencing the $crit property, meaning the value of the variable $crit is evaluated to a string, then that string value is used as the property name.

What's $crit defined as? I'll bet it's not the string 'crit'!

Charles