gpt4 book ai didi

PHP 类 - fatal error : Can't use method return value in write context

转载 作者:可可西里 更新时间:2023-10-31 23:53:46 24 4
gpt4 key购买 nike

<?php /* my function class */
class dbFunctions{
public $dbHost = "localhost",
$dbLogin = "root",
$dbPwd = "",
$dbName = "forex",
$mysqli;

/* Create a new mysqli object with database connection parameters */
public function __construct(){
$this->mysqli = new mysqli($this->dbHost, $this->dbLogin, $this->dbPwd , $this->dbName);
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
}
public function address(){
if($stmt = $this->mysqli -> prepare("SELECT `email_content` FROM `content` WHERE `content_name`= ? ")) {
$content = 'address';
$stmt -> bind_param("s", $content);
$stmt -> execute();
$stmt -> bind_result($result);
$stmt -> fetch();
$stmt -> close();
echo $result;
}
}
}
$obj = new dbFunctions() ;
?>

<!-- MY FOOTER FILE WHERE I CALLED THE FUNCTION-->
<div id="address">
<a href="#" style="color:#fff; text-decoration:none;"> Contact Us:</a>
<?php if(!empty($obj->address())){?><?php $obj->address();?>
<?php }?>
</div>

fatal error :无法在第 3 行的 C:\wamp\www\forex\includes\footer.html 的写入上下文中使用方法返回值

请帮我解决这个问题..我搜索了很多但没有找到任何解决方案。

最佳答案

问题出在第 3 行的页脚中:

<?php if(!empty($obj->address())){?><?php $obj->address();?>

来自 PHP 手册:

Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.

你必须将 $obj->address() 设置到它自己的变量中,并用 empty() 测试这个变量。

关于PHP 类 - fatal error : Can't use method return value in write context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19175675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com