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.

2

3 Answers 3

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().

Sign up to request clarification or add additional context in comments.

Comments

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());?>

4 Comments

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 - How can you say that my php version is low? Mine is 5.4.3 ,should i upgrade?
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 - thumbs up! I'll upgrade test and reply!
0

See below:

<?php if(trim($obj->address()) != ''){?><?php $obj->address();?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.