3
<?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: Can't use method return value in write context in C:\wamp\www\forex\includes\footer.html on line 3

Please help me out of this issue..I've searched a lot and have not found any solution.

user2845577
  • 123
  • 2
  • 2
  • 6
  • 2
    possible duplicate of [Can't use method return value in write context](http://stackoverflow.com/questions/1075534/cant-use-method-return-value-in-write-context) – Pupil Oct 04 '13 at 07:33
  • please refer it to here: http://stackoverflow.com/questions/1075534/cant-use-method-return-value-in-write-context – Pupil Oct 04 '13 at 07:34

3 Answers3

18

The problem is in the footer in line 3:

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

From the PHP manual:

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.

You have to set $obj->address() into its own variable, and test this variable with empty().

Benno Eggnauer
  • 853
  • 1
  • 7
  • 19
0

function address() doesn't return anything, so you can't use empty($obj->address()) :

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();
        return $result;
    }
    return false;
}

and for the display:

<?php if(!empty($obj->address())){?><?php print_r($obj->address());?>
zerokavn
  • 1,333
  • 1
  • 9
  • 10
  • If a function is returning "nothing" it returns `NULL` so it's absolutely valid and perfect for `empty()`. But his PHP version is to low, so it won't work. – Fleshgrinder Oct 04 '13 at 07:44
  • @Fleshgrinder - How can you say that my php version is low? Mine is 5.4.3 ,should i upgrade? – user2845577 Oct 04 '13 at 08:53
  • Correct, if you use "echo" in function address() instead of "return". The "empty" function won't work with 5.4.3, you must have 5.5 or higher. – zerokavn Oct 04 '13 at 08:58
  • @zerokavn - thumbs up! I'll upgrade test and reply! – user2845577 Oct 04 '13 at 09:17
0

See below:

<?php if(trim($obj->address()) != ''){?><?php $obj->address();?>
Nes
  • 304
  • 1
  • 10