We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon update affecting magic methods?

Hi there,

a little while ago I have build a phalcon app (MVC) based on phalcon 2.0.1 (compiled from source at the time).

Now, after a system update on my computer, I had to reinstall phalcon and I took the fast routeof using the the macports repository. Phalcon is at 2.0.7 now. And suddenly I get an error about an undefined method on one of my models.

The method in question is called "hasAbility" and is indeed not explicitly defined in the model class. So my guess (I can't really remember) is that it is some kind magic function that works directly with a related model class.

The 3 models concerned in this setup are:

  • Users.php
  • Abilities.php
  • UsersAbilities.php

The following are the initialize methods of two of these model classes. The Abilities.php class does not have this method.

    // Users.php
    public function initialize()
    {
        $this->hasMany("id", "UsersAbilities", "user_id", array('foreignKey' => TRUE));
        ...
    }

    // UsersAbilities.php
    public function initialize() {
        $this->belongsTo("user_id", "Users", "id", array(
            "foreignKey" => TRUE,
        ));
        $this->belongsTo("ability_key", "Abilities", "machine_name", array(
            "foreignKey" => TRUE,
            'alias' => 'Ability',
        ));
    }

This setup works flawlessly in phalcon 2.0.1 (and I think even in 2.0.2 which was installed later on my computer but before the system update). But now it throws an error.

Now my question: Is this supposed to fail in newer phalcon versions. Or is there a problem with my setup? Also I can't find documentation for older phalcon versions but I'm pretty sure that I didn't come up with this on my own. If anyone could point me to some docs on this subject that might be helpful.

Thanks in advance.



34.6k
Accepted
answer

There was a bug in 2.0.1 that when you can an undefined method it did not throw an exception, now that it is fixed you see that method does not exist



2.1k

Ah!! Thanks for clearing that up!

There was a bug in 2.0.1 that when you can an undefined method it did not throw an exception, now that it is fixed you see that method does not exist