Php laravel抽象方法致命异常错误

Php laravel抽象方法致命异常错误,php,laravel,laravel-4,Php,Laravel,Laravel 4,我使用的是Laravel4附带的用户类。我试图存储一个属于用户的新问题,用户需要登录才能创建。当我调用questions controller action store时,我得到以下错误 Class User contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (Illuminate\Auth\UserInterface::getAuthPas

我使用的是Laravel4附带的用户类。我试图存储一个属于用户的新问题,用户需要登录才能创建。当我调用questions controller action store时,我得到以下错误

Class User contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (Illuminate\Auth\UserInterface::getAuthPassword, Illuminate\Auth\Reminders\RemindableInterface::getReminderEmail)
我已经阅读了一些php中的抽象方法,虽然我不完全理解它们,但错误本身给出了两种解决问题的方法,声明了实现remaing方法的类抽象。我猜想,由于这是laravel附带的模型类,正确的解决方案不是将其声明更改为抽象,而是实现其余的方法。在这种情况下,我如何正确地执行此操作

用户模型

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends BaseModel implements UserInterface, RemindableInterface {

    protected $guarded = [];

    public static $rules = array(
        'username' => 'required|unique:users|alpha_dash|min:4',
        'password' => 'required|alpha_num|between:4,8|confirmed',
        'password_confirmation'=>'required|alpha_num|between:4,8' 
        );

    public function Questions($value='')
    {
        return $this->hasMany('Question');

    }

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password');

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }

}
编辑1:错误消息包括“(Illumb\Auth\UserInterface::getAuthPassword,Illumb\Auth\Reminders\RemindableInterface::GetRemindableMail)”这两个方法在my user.php中作为公共函数存在,正如您在上面所看到的,所以我是否需要执行其他操作来“实现”它们

编辑2:

Laravel Src用户接口类

<?php namespace Illuminate\Auth;

interface UserInterface {

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier();

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword();

}
基本模型类

<?php

class Basemodel extends Eloquent {

    public static function validate($data) {

        return Validator::make($data, static::$rules);
    }
}


?>

也许用一个例子来回答这个问题最简单。假设我有以下课程:

abstract class ClassB {
    public abstract function foo();
}

class ClassA extends ClassB {}

$a = new ClassA();
运行此代码将导致以下错误:

Fatal error: Class ClassA contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (ClassB::foo)
这意味着我在
ClassA
中缺少
foo()
(在
ClassB
中定义)的实现。抽象方法只能在抽象类中定义,这意味着任何非抽象派生类都必须公开完整的实现,而在这种情况下,
ClassA
不会。可以通过将
ClassA
更改为

class ClassA extends ClassB {

    // implementation of abstract ClassB::foo().
    public function foo() {
        echo 'Hello!';
    }
}

回到你的例子。您的
User
类扩展了
BaseModel
。根据
BaseModel
是否扩展了另一个抽象类,它将包含两个定义为
abstract
的方法,您的
User
类缺少这两个方法。您需要找到这些方法—我的错误消息明确地告诉了我缺少什么—并在
User

中实现它们—您能将这两种方法的完整签名添加到您的问题中吗?您必须确保实现的签名匹配(具有相同或更高的可见性)。我不完全确定完整签名的含义抱歉,但我猜了一下,看看edit 2这很奇怪,尤其是
getAuthIdentifier()
方法似乎很好。是否在
-1
上报告错误?如果您将
User
更改为不扩展
BaseModel
并尝试仅实例化它,您是否看到任何错误?我添加了php.ini中与错误报告相关的部分。如果这个类没有扩展basemodel,它就没有扩展雄辩的orm,这将彻底破坏应用程序。我承认我自己没有想法。也许OO PHP有一个我不知道的复杂之处。
getAuthIdentifier()
getAuthPassword()
之间肯定有区别,但我找不到它。。。
<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class Question extends BaseModel implements UserInterface, RemindableInterface {

    protected $guarded = [];

    public static $rules = array(
            'questions'=>'required|min:10|max:255',
            //'solved'=>'in:0,1',
        );

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'questions';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('');

    /**
     * Get the unique identifier for the question.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    public function user()
    {
        return $this->belongsTo('User');
    }

}
/**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }
abstract class ClassB {
    public abstract function foo();
}

class ClassA extends ClassB {}

$a = new ClassA();
Fatal error: Class ClassA contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (ClassB::foo)
class ClassA extends ClassB {

    // implementation of abstract ClassB::foo().
    public function foo() {
        echo 'Hello!';
    }
}