Fatal error: Cannot override final method Phalcon\Mvc\Model::__construct()
Fatal error: Cannot override final method Phalcon\Mvc\Model::__construct() in Group.php on line 9
I'm getting this error even though the Group model has no __construct() function (and there are no descending classes).
Simply 'touch'-ing the file (or an Apache restart) seems to resolve the issue (temporarily);
Complete signature for the class:
use Phalcon\Mvc\Dispatcher\Exception;
use Phalcon\Mvc\Model\Behavior\Timestampable,
Phalcon\Mvc\Model\Validator\Inclusionin,
PrimaDeluxe\Format
;
class Group extends \Phalcon\Mvc\Model implements ElasticInterface
{
const TYPE_OPEN = 'open';
const TYPE_CLOSED = 'closed';
const TYPE_PRIVATE = 'private';
static $ALL_TYPES = array(self::TYPE_OPEN, self::TYPE_CLOSED, self::TYPE_PRIVATE);
/**
* @var integer
*
*/
public $id;
/**
* @var string
*
*/
public $type;
/**
* @var string
*
*/
public $title;
/**
* @var string
*
*/
public $body;
/**
* @var string
*
*/
public $created;
/**
* @var string
*
*/
public $modified;
public function initialize()
{
$this->hasMany('id', 'GroupMember', 'group_id');
$this->hasMany('id', 'Message', 'group_id');
$this->hasMany('id', 'Label', 'group_id');
$this->hasMany('id', 'Notification', 'group_id');
$this->addBehavior(new Timestampable(array(
'beforeCreate' => array(
'field' => 'created',
'format' => 'Y-m-d H:i:s'
)
)));
$this->addBehavior(new Timestampable(array(
'beforeUpdate' => array(
'field' => 'modified',
'format' => 'Y-m-d H:i:s'
)
)));
$this->addBehavior(new ElasticBehaviour());
}
public function beforeValidationOnCreate()
{
if(!isset($this->type)){
$this->type = 'open';
}
}
public function validation()
{
$this->validate(new Inclusionin(array(
'field' => 'type',
'domain' => self::$ALL_TYPES
)));
return $this->validationHasFailed() != true;
}
/**
* @param array $parameters
* @return Group[]
*/
public static function find($parameters=array())
{
return parent::find($parameters);
}
/**
* @param array $parameters
* @return Group
*/
public static function findFirst($parameters=array())
{
if(!$parameters){
return new Group();
}
return parent::findFirst($parameters);
}
/**
* @param int $limit
* @param int $page
* @param null $types
* @return Group[]
*/
public static function findLatest($limit=10, $page=0, $types=null )
{
}
/**
* @param int $limit
* @param int $page
* @return Group[]
*/
public static function findLatestByType($type=self::TYPE_OPEN, $limit=10, $page=0)
{
}
/**
* @param string $group_status
* @param string $member_status
* @return array|Member[]
*/
public function findMembers($group_status=GroupMember::STATUS_ACTIVE, $member_status=Member::STATUS_ACTIVE, $limit=null)
{
}
/**
* @param string $group_status
* @param string $member_status
* @return Member[]
*/
public function findAdmins($group_status=GroupMember::STATUS_ACTIVE, $member_status=Member::STATUS_ACTIVE)
{
}
/**
* @return Member[]
*/
public function findMembersReceivingNotifications()
{
}
/**
* @param Member $member
* @throws Exception
*/
public function requestAccess(Member $member)
{
}
/**
* @param Member $admin
* @param array $member_data
* @return Member[]
* @throws Exception
*/
public function invite(Member $admin, $member_data)
{
}
/**
* @param string|array $types
* @param int $limit
* @param int $page
* @param string $order
* @return Message[]
*/
public function findMessages($types=Message::TYPE_DISCUSSION, $limit=null, $page=0, $order = 'created DESC')
{
}
/**
* @param string $label
* @param string $types
* @param int $limit
* @param int $page
* @param string $order
* @return \Phalcon\Mvc\Model\QueryInterface
*/
public function findMessagesLabeled($label, $types=Message::TYPE_DISCUSSION, $limit=null, $page=0, $order = 'Message.created DESC')
{
}
/**
* @return array
*/
public function findLabelCounts()
{
}
/**
* @param int $limit
* @param int $page
* @param string $order
* @return Message[]
*/
public function findOpenTasklists($limit=null, $page=0, $order = 'm.created DESC')
{
}
/**
* @param bool $prefix
* @return string
*/
public function getURI($prefix=true)
{
}
/**
* ElasticInterface implementation
*
* @return \Elastica\Document
*/
public function toElasticDocument()
{
}
/**
* @return string
*/
public function getElasticType()
{
}
}
The class is implementing an interface, a fact which seems to be related to the issue
interface ElasticInterface
{
public function getElasticType();
public function toElasticDocument();
}
Any ideas what could be causing this behaviour?
Hi, You should to use forum to ask the questions
I ran your code, it works fine on Phalcon 1.1.0
What is ElasticBehaviour?
May be you have inherited it from Phalcon\Mvc\Model?
Hi Agent-J,
Thanks for your reply. Maybe I shouldn't have posed the question in the end.
Still the issue remains the same: The error message seems to be completely unrelated to the code that I have. This ~ to me ~ appears to be a bug, as the error message should help me determine what went wrong. As it stands it clearly doesn't help as the __construct() function does not exist in the Group class.
I've noticed this first on Phalcon 1.0.1, and have since upgraded to 1.1.0 but still get the error on occasion - note that it doesn't always appear. I'm using PHP 5.4.14 on CentOS 6.4 with Apache 2.2.15. Memcache and memcached extensions are installed but not used. I'm also using APC 3.1.15-dev - which may or may not be involved.
ElasticBehaviour:
use Phalcon\Mvc\Model\Behavior,
Phalcon\Mvc\Model\BehaviorInterface,
Elastica\Client;
class ElasticBehaviour extends Behavior implements BehaviorInterface
{
public function __construct($options=null)
{
$this->_options = $options;
}
/**
* @see http://docs.phalconphp.com/en/latest/reference/models.html#events-and-events-manager
* @param string $eventType
* @param \Phalcon\Mvc\ModelInterface $model
*/
public function notify($eventType, $model)
{
if (!($model instanceof ElasticInterface))
{
throw new Exception('Model $model should implement interface ElasticInterface');
}
switch ($eventType) {
case 'afterCreate':
case 'afterUpdate':
$this->uploadElastic($model);
break;
case 'afterDelete':
$this->removeElastic($model);
break;
default:
/* ignore the rest of events */
}
}
private function getIndex()
{
$client = new Client();
$index = $client->getIndex('ppi');
$index->open();
return $index;
}
/**
* Add document to search index
*
* @param ElasticInterface $model
*/
private function uploadElastic($model)
{
// Check if insert_rule applies
if (is_array($this->_options) && isset($this->_options['insert_rule']))
{
$insert_rule = $this->_options['insert_rule'];
if (!$insert_rule($model))
return;
}
// Check if delete_rule applies
if (is_array($this->_options) && isset($this->_options['delete_rule']))
{
$delete_rule = $this->_options['delete_rule'];
if ($delete_rule($model))
{
$this->removeElastic($model);
return;
}
}
// Store document
try
{
$index = $this->getIndex();
$modelType = $index->getType(strtolower($model->getElasticType()));
$doc = $model->toElasticDocument();
$doc->setType($modelType);
// Adds document to the index
$modelType->addDocument($doc);
}
catch (Exception $e) {
// ignore it?
}
}
/**
* Removes document from search index
*
* @param ElasticInterface $model
*/
private function removeElastic($model)
{
try
{
$index = $this->getIndex();;
$modelType = $index->getType(strtolower(get_class($model)));
$modelType->deleteById($model->id);
}
catch (Exception $e) {
// ignore it?
}
}
}
I have tested in Ubuntu with 5.4.13, on Windows with 5.4.7 and on Mac with PHP 5.5rc1, without be able to reproduce the problem.
Can you try disabling APC? Why do you need this specific version APC 3.1.15-dev? Can you try with the stable version of APC?
I'll see what happens without APC & close for now as it's not reproducible.