Last Updated: July 25, 2019
·
838
· antony492

Fix Errors Whilst Using Referenced Functions

This function would return an error when called:

function &getAllElements ( ) {
    if (is_array($this->data)) {
        return $this->data;
    }
    return null;
}

The error would be something along the lines of:
"Only variable references should be returned by reference."

A quick and dirty way (and the only way I could figure out) is to set a variable with your null value and return that:

function &getAllElements ( ) {
    if (is_array($this->data)) {
        return $this->data;
    }
    $null = null;
    return $null;
}

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside