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

Bug? Phalcon 4. Trying to call method getrelationbyalias on a non-object

Experience with Phalcon 3.4 is great. But I can’t start Phalcon 4. When creating any model, they write an error in the header

$ zephir fullclean
$ zephir build
 Preparing for PHP compilation...
 Preparing configuration file...
 Compiling...
 Installing...

 Extension installed.

 ! [NOTE] Don't forget to restart your web server                                                                       

$ sudo service php7.4-fpm restart
class IndexController extends Phalcon\Mvc\Controller
{
    public function indexAction()
    {
        $form = new Form();
    }
}
class Form extends Phalcon\Mvc\Model {

    public $formID;
    public $name;
    public $data;
    public $date_add;
    public $userID;
    public $parentID;

    public function initialize() {
        $this->setSource('gl_form');
    }
}

ERROR: Trying to call method getrelationbyalias on a non-object

Ubuntu 19 Mysql 8



85.5k

it seems like you didnt boot the DI/Application class. Could you try clonning vokuro https://github.com/phalcon/vokuro and see it from there. I guess you are missing some small code that will make it work

edited May '20

Minimum configuration required:

<?php
use Phalcon\Loader;
use Phalcon\Mvc\Application;
use Phalcon\Mvc\View;
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\Di\FactoryDefault;

define('BASE_PATH', dirname(__DIR__));
define('APP_PATH', BASE_PATH . '/app');

$loader = new Loader();

$loader->registerDirs(
    [
        APP_PATH . '/controllers/',
        APP_PATH . '/models/',
    ]
);

$loader->register();

$container = new FactoryDefault();
$container->set(
    'view',
    function () {
        $view = new View();
        $view->setViewsDir(APP_PATH . '/views/');
        return $view;
    }
);

$container->set(
    "db",
    function () {
        return new Mysql(
            [
                "host"     => "127.0.0.1",
                "username" => "root",
                "password" => "",
                "dbname"   => "dev",
            ]
        );
    }
);
$application = new Application($container);

try {
    $response = $application->handle(
        $_SERVER["REQUEST_URI"] ?? '/'
    );
    $response->send();
} catch (\Exception $e) {
    echo 'Exception: ', $e->getMessage();
}
edited May '20

Try Vokuro:

Trying to call method getrelationbyalias on a non-object
#0 /mnt/web/domains/test1/src/Controllers/SessionController.php(49): Phalcon\Mvc\Model->__isset()
#1 [internal function]: Vokuro\Controllers\SessionController->signupAction()
#2 [internal function]: Phalcon\Dispatcher\AbstractDispatcher->callActionMethod()
#3 [internal function]: Phalcon\Dispatcher\AbstractDispatcher->dispatch()
#4 /mnt/web/domains/test1/src/Application.php(71): Phalcon\Mvc\Application->handle()
#5 /mnt/web/domains/test1/www/index.php(28): Vokuro\Application->run()
#6 {main}


85.5k

are you sure you are executing the correct php code/path? i don't know to be honest, by pure geuesswork i think some small misstake within vhost/your code

edited May '20

Of course. All that we managed to test, works correctly exactly until the moment when the request for the model class occurs. Any model. For example new Users(

https://i.imgur.com/UXsHw9H.png

Codeception Test Vakuro:

---------
1) EmailConfirmationsTest: Model instance of
 Test  tests/unit/models/EmailConfirmationsTest.php:testModelInstanceOf

  [RuntimeException] Trying to call method getrelationbyalias on a non-object  

#1  Phalcon\Mvc\Model->__isset
#2  /mnt/web/domains/test1/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Instantiator.php:73
#3  /mnt/web/domains/test1/vendor/doctrine/instantiator/src/Doctrine/Instantiator/Instantiator.php:62
#4  PHPUnit\Framework\MockObject\Generator->getMock
#5  /mnt/web/domains/test1/tests/unit/models/EmailConfirmationsTest.php:14

https://i.imgur.com/vISeihO.png

edited May '20

@alexdecc Could you please try current 4.0.x branch?

4.0.6 - the result is the same when building through zephir build



414
Accepted
answer

I managed to get this to work by building it like this (without using it zephir):

git clone --depth=1 "git://github.com/phalcon/cphalcon.git"
cd cphalcon/build
sudo ./install

phalcon.so - version: 4.0.5 - works!

I had the same problem and I solved it by not checking out tag v4.0.0

git checkout tags/v4.0.0 ./

in https://docs.phalcon.io/4.0/en/installation#compile-from-sources



10.1k

Phalcon 4.0.6 is compatible with Zephir 0.12.17. Newer Zephir versions will be used on the 4.1 release.