PHP, is_array() generating an "Undefined property: stdClass::$crit " error
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?
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).
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
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'!
加载中,请稍侯......
精彩评论