学习php oop - 无法反转数组

Bil*_*rer 1 php oop

我正在学习PHP OOP,我试图理解为什么以下脚本不起作用:

class ShowTimeline {
    var $conn;
    var $rev;

    function getTimeline ($conn) {
        return $this->conn;
    }

    function reverseTimeline () {
        $rev = array_reverse($this->conn, false);
        return $rev;
    }

    function display () {
        $this->reverseTimeline();
        print_r($this->rev);
    }
}
print '<hr />';
$connect = new showTimeline();
$connect->conn = array('one', 'two', 'three');
$connect->display();
Run Code Online (Sandbox Code Playgroud)

当我将脚本更改为:

//same stuff above
function display () {
            $this->reverseTimeline();
            print_r($this->conn); //changed from $this->rev
        }
//same stuff below
Run Code Online (Sandbox Code Playgroud)

我打印出来了:

Array ( [0] => one [1] => two [2] => three )
Run Code Online (Sandbox Code Playgroud)

哪个是对的.请帮忙?

hsz*_*hsz 6

使用访问类的参数$this->.

function reverseTimeline () {
    $this->rev = array_reverse($this->conn, false);
    return $this->rev;
}
Run Code Online (Sandbox Code Playgroud)

使用$rev它只被视为局部变量.