クラスとして別のphpファイルの変数を使用したい。しかし、常にエラーが発生します: Notice: Undefined variable:...
最初: ユーザー オブジェクトを作成します。 ファイル: index.php
<?php
// include the configs / constants for the db connection
require_once("config/config.php");
// load the user class
require_once("classes/User.php");
$user = new User();
include("views/order.php");
ファイル: User.php
class User
{
public $color = "green";
}
ファイル livesearch.php
require_once("../classes/User.php");
echo $User->color;
私は index.php ファイルでクラス user からオブジェクトを作成します。そこでも User.php ファイルに一度必要としますが、それは機能します。クラスの変数にアクセスできないのはなぜですか?