PHP:未定义的变量 [英] PHP: Undefined variable

查看:179
本文介绍了PHP:未定义的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码。由于某种原因,当我运行这个代码,它说变量rsLinks是未定义的。但是很清楚,你可以看到它是在构造函数中定义的。你能告诉我我做错了什么吗?

I have the code below. For some reason when I run this code it say the variable rsLinks is undefined. Yet clearly you can see that it is defined in the constructor. Can you tell me what I am doing wrong?

 require_once "..\Models\Links.php";

class Navigator
{
    public $rsLinks;

    public function __construct() 
    { 
        $rsLinks = new rsLinks();
    }

    public function getLinks()
    {
        $links = $rsLinks;
    }
}

$navigator = new Navigator();
$navigator->getLinks();


推荐答案

使用 $ this- ; rsLinks;

这篇关于PHP:未定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆