简体   繁体   中英

PHP, Fatal error: Call to undefined method calling function from another class

I have a simple PHP structure.

In admin_keys.php i have:

<?php
class admin_keys
{
    public $key;
    private $arr_keys = array("1", "2", "3");
    public function check_key_admin()
    {
        if(in_array($this->key,$this->$arr_keys))
        {
            return true;
        }else
        {
            return false;
        }
    }
}
?>

In ok.php i have:

<?php
include_once '../../all_keys.php';
$admin_keys = new admin_keys();
$admin_keys->key = "vailozluon";
$_isAdmin = $admin_keys->check_key();
  if( _isAdmin== false)
  {
    echo 'deo phai';
  }else { echo 'ok';}
?>

Im new so just bear with me I don't know why this is return Uncaught Error: Call to undefined method admin_keys::check_key any help will be appreciated.

thanks!

you are refering to function (ie check_key()) that does not exists in your class admin_keys . You have function named check_admin_key() but you are trying to access it as check_key() which does not exist apparently throwing an error. So just change the name of the function being called as

$_isAdmin = $admin_keys->check_admin_key();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM