我有这个:
$classname)$propertyname)我想从该类中获取该属性,问题是,属性是静态的,我不知道该怎么做.
如果属性不是静态的,那将是:
$classname->$propertyname;
Run Code Online (Sandbox Code Playgroud)
如果属性是一个方法,我可以使用call_user_function
call_user_func(array($classname, $propertyname));
Run Code Online (Sandbox Code Playgroud)
但就我而言,我只是输了.但我希望这是可能的.有了PHP拥有的数千个函数,他最好还有一些东西.也许我错过了什么?
谢谢!
编辑:
我试图从我的数据库表中输出一些内容,我成功地进行了查询并返回控制器代码但是当我在我的视图中尝试输出它时,我尝试了什么
<tr>
<?php foreach ($products as $product) { ?>
<td>
<pre>
<?php
var_dump($products[$product['product_id']]['manufacturers']);
foreach ($products[$product['product_id']]['manufacturers'] as $manufacturer) {
echo $manufacturer;
} ?>
</pre>
</td>
<?php } ?>
</tr>
Run Code Online (Sandbox Code Playgroud)
错误
注意:第72行的C:\ xampp\htdocs\usa\catalog\view\theme\usadevims\template\product\compare.tpl中的数组到字符串转换ArrayNotice:C:\ xampp\htdocs\usa\catalog中的数组到字符串转换第72行的\ view\theme\usadevims\template\product\compare.tplArrayNotice:第72行的C:\ xampp\htdocs\usa\catalog\view\theme\usadevims\template\product\compare.tpl中的数组到字符串转换
这里是我的变量的var_dump
array(3) {
[0]=>
array(2) {
["name"]=>
string(5) "Apple"
["manufacturer_id"]=>
string(1) "8"
}
[1]=>
array(2) {
["name"]=>
string(3) "HTC"
["manufacturer_id"]=>
string(1) "5"
}
[2]=>
array(2) {
["name"]=>
string(4) "Sony"
["manufacturer_id"]=>
string(2) "10"
}
}
Run Code Online (Sandbox Code Playgroud)