简体   繁体   English

php对象数组无法获取对象属性(stdClass类的对象无法转换为字符串)

[英]php array of objects can't get object property (Object of class stdClass could not be converted to string)

been searching for a solution all day long... 整天都在寻找解决方案...

my variable name is $categoryFetchedAsObj var_dump results : 我的变量名称是$ categoryFetchedAsObj var_dump结果:

array(104) {
[0]=>
object(stdClass)#411 (1) {
["categoryHive"]=>
string(4) "asfa"
}

[1]=>
object(stdClass)#412 (1) {
["categoryHive"]=>
string(13) "ENERGY DRINKS"
}

[2]=>
object(stdClass)#413 (1) {
["categoryHive"]=>
string(7) "KETCHUP"
}

[3]=>
object(stdClass)#414 (1) {
["categoryHive"]=>
string(6) "STICKS"
}

and so on 等等

i call a function... 我调用一个函数...

createSelectBlock("category",$categoryFetchedAsObj,"onchange=\"this.form.submit()\"",null,'categoryHive');

here is the instance of the function 这是函数的实例

createSelectBlock($name,$fetchedNamesAsArrayOfObj,$selectEvent,$objPropertyNameForOptionsValue,$objPropertyNameForOptionsName) createSelectBlock($ name,$ fetchedNamesAsArrayOfObj,$ selectEvent,$ objPropertyNameForOptionsValue,$ objPropertyNameForOptionsName)

and here is where the error raises 这是引发错误的地方

foreach ($fetchedNamesAsArrayOfObj as $rowArrayObj) {

                if(isset($objPropertyNameForOptionsValue) && isset($objPropertyNameForOptionsName)){
                $selectBlock.="<option value=\"$rowArrayObj->$objPropertyNameForOptionsValue\">$rowArrayObj->$objPropertyNameForOptionsName</option>";
                }
                if(!isset($objPropertyNameForOptionsValue) && isset($objPropertyNameForOptionsName)){
                $selectBlock.="<option value=\"$rowArrayObj->$objPropertyNameForOptionsName \">$rowArrayObj->$objPropertyNameForOptionsName</option>";
                }

        }               

(Object of class stdClass could not be converted to string) (无法将类stdClass的对象转换为字符串)

if i replace the $rowArrayObj->$objPropertyNameForOptionsName with 如果我将$ rowArrayObj-> $ objPropertyNameForOptionsName替换为

$rowArrayObj->categoryHive

everything works but the args of the function are not the same all the time .. obviously 一切正常,但函数的参数始终不相同..显然

i search this site found some suggestions.. but nothing worked here is what i tryied 我搜索该网站发现了一些建议..但是这里没有任何工作是我尝试过的

$objPropertyNameForOptionsName='$objPropertyNameForOptionsName';
$rowArrayObj->{'$objPropertyNameForOptionsName'};

any ideas? 有任何想法吗?

after testing and over testing .. finlay i got it working... this was the correct answer for my situation 经过测试和过度测试.. finlay我得到了工作...这是我的情况的正确答案

if(isset($objPropertyNameForOptionsValue) && isset($objPropertyNameForOptionsName)){
                     $selectBlock.="<option value=".$rowArrayObj->$objPropertyNameForOptionsValue.">".$rowArrayObj->$objPropertyNameForOptionsName."</option>";
}
if(!isset($objPropertyNameForOptionsValue) && isset($objPropertyNameForOptionsName)){
                $selectBlock.="<option value=".$rowArrayObj->$objPropertyNameForOptionsName.">".$rowArrayObj->$objPropertyNameForOptionsName."</option>";
}

hope it helped someone 希望它能帮助某人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类stdClass的PHP对象无法转换为字符串 - PHP Object of class stdClass could not be converted to string 无法将类stdClass的对象转换为字符串PHP - Object of class stdClass could not be converted to string PHP “类stdClass的对象无法转换为字符串” php - “Object of class stdClass could not be converted to String” php 类stdClass的PHP数组对象无法转换为字符串 - PHP array Object of class stdClass could not be converted to string PHP SoapClient:类stdClass的对象无法转换为字符串 - PHP SoapClient: Object of class stdClass could not be converted to string PHP Laravel错误:类stdClass的对象无法转换为字符串 - PHP Laravel Error: Object of class stdClass could not be converted to string 在php codeigniter中,类stdClass的对象无法转换为字符串 - Object of class stdClass could not be converted to string in php codeigniter PHP Catchable 致命错误:无法将类 stdClass 的对象转换为字符串 - PHP Catchable fatal error: Object of class stdClass could not be converted to string 类stdClass的对象无法转换为字符串PHP问题 - Object of class stdClass could not be converted to string PHP issue 访问数组时,类stdClass的对象无法转换为字符串错误 - Object of class stdClass could not be converted to string error when accessing array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM