Yii Framework Forum

Yii 1.1 - ActiveRecord with() Causing Error In PHP 5.6


(Sven Kauber) #1

I moved a project from a server that had a PHP 5.3 installation to another, more modern one that has PHP 5.6. Now the part of the code where ActiveRecord’s find() is used for the first time causes the following error:




Fatal error: Call to undefined method Locale::attachBehaviors() in /var/www/lib/yii-1.1.16.bca042/framework/db/ar/CActiveRecord.php on line 396



Locale is a custom class that is inheriting from CActiveRecord. The class has the usual required functions defined:




public function tableName(){...}

public static function model($className=__CLASS__)[...}



The "with()"- part that is causing the error is in a base controller where find() is used like this:




$user = User::model()->with(array('locale'))->find(array(

	'condition' => 'instanceId=:instanceId',

	'params' => array(':instanceId' => $this->instanceId),

	'order'=>'t.id DESC'

));



Attached is the output from XDebug. Things start to go wrong after the Controller.php:49-line.

6885

xdebug.jpg


(Alexander Makarov) #2

Is it 1.1.16? Any clear way to reproduce it with clean application?


(Sven Kauber) #3

Yes, it is 1.1.16. A clean project worked well and then I continued by adding Locale and User classes to the models directory to emulate the issue. All worked well right until I added the find() part to the default SiteController, used by the clean test project. Without the "with()" part, the user was loaded normally but the "with()" activated the "Call to undefined method Locale::attachBehaviors()" error. Here is attached a screenshot.

Please see the changed files on PasteBin:

Locale.php (should go to protected/models)

http://pastebin.com/gd8wQ7Tf

User.php (should go to protected/models)

http://pastebin.com/Raqwcv1a

SiteController.php (located at protected/controllers)

http://pastebin.com/m8GA2WA1

SQL Dump:

http://pastebin.com/z2WwaDfi

EDIT - About the server:

Set up using DigitalOcean’s minimal Debian setup with 512 MB of memory. Its version is “Debian GNU/Linux 8.2 (jessie)”. The package manager was used to install the latest nginx, php5-related packages and the guidelines were followed to set it up so that it works with Yii.

I am using a separate server for the database, and both servers are set up into a local network. My database connection string looks like this:




return array(

	'connectionString' => 'mysql:host=10.131.109.56;port=3306;dbname=test',

	'username' => 'test',

	'password' => 'password_is_here',

	'charset' => 'utf8',

);



Below are the packages that I have installed for the LEMP stack into the web server:

php-pear

php5-cli

php5-common

php5-curl

php5-dev

php5-fpm

php5-gd

php5-imagick

php5-intl

php5-json

php5-mcrypt

php5-memcache

php5-mysql

php5-readline

php5-xdebug

mysql-client

mysql-client-5.5

mysql-common

nginx

nginx-common

nginx-full


(Pawel) #4

Isn’t this because of Locale PHP class?

Have you tried to change the name?


(Sven Kauber) #5

Bizley, that was the reason! Thank you!


(Alexander Makarov) #6

Good catch, Bizley. Thanks!


(Pawel) #7

Cheers.

You know @sven - this wouldn’t happen with Yii 2 and namespaces :P