Class variable is null when I try to access it in PHP

后端 未结 1 780
迷失自我
迷失自我 2021-01-28 00:03

Alright, this is my main code:

require \"checkpassword.php\";
require \"mysqllogininfo.php\";

# Validate password
if (!validatePassword($_GET[\"password\"])         


        
相关标签:
1条回答
  • 2021-01-28 00:14

    No where in your MySQLLoginInfo constructor do you actually set the class variables, only the local function variables:

    #Loop through lines
    while (($line = fgets($handle)) !== false) {
        if ($i === 0)
            $this->host = $line; // vs $host = $line;
        // ...
    }
    

    I refer you to the documentation on Class Properties:

    Within class methods non-static properties may be accessed by using -> (Object Operator): $this->property (where property is the name of the property). Static properties are accessed by using the :: (Double Colon): self::$property. See Static Keyword for more information on the difference between static and non-static properties.

    0 讨论(0)
提交回复
热议问题