B
B
bqio2016-08-01 09:17:32
PHP
bqio, 2016-08-01 09:17:32

Why error while executing PHP script?

There are two files index.php and member.php
index.php

<?php

require_once 'app/member.php';

$user = new member();
echo $user->username;

member.php
<?php

namespace app;

class member
{
  public $username = '';
  private $login_status = false;

  public function login()
  {
    $this->login_status = true;
  }

  public function logout()
  {
    $this->login_status = false;
  }

  public function islogin()
  {
    return $this->login_status;
  }
}

When opening index.php file
Fatal error: Class 'member' not found in Z:\home\localhost\www\_php\index.php on line 5
What's the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2016-08-01
@bqio

Read php.net/manual/ru/language.namespaces.php for example.
Because member is in the namespace app and accordingly you need to write
PS Since we started using namespace, it is logical to start using autoload php.net/manual/ru/language.oop5.autoload.php , it's very convenient.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question