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

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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

#1 User is offline   sven 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 20-February 09

Posted 21 December 2015 - 10:02 AM

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.

Attached File  xdebug.jpg (219.27K)
Number of downloads: 3
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,184
  • Joined: 17-January 09
  • Location:Russia

Posted 21 December 2015 - 05:07 PM

Is it 1.1.16? Any clear way to reproduce it with clean application?
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#3 User is offline   sven 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 20-February 09

Posted 22 December 2015 - 01:44 PM

View Postsamdark, on 21 December 2015 - 05:07 PM, said:

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


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

Attached File(s)


0

#4 User is offline   Bizley 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 922
  • Joined: 29-July 14
  • Location:Wrocław

Posted 22 December 2015 - 03:18 PM

Isn't this because of Locale PHP class?
Have you tried to change the name?
http://bizley.pl ʕ•ᴥ•ʔ
0

#5 User is offline   sven 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 20-February 09

Posted 23 December 2015 - 02:31 PM

View PostBizley, on 22 December 2015 - 03:18 PM, said:

Isn't this because of Locale PHP class?
Have you tried to change the name?


Bizley, that was the reason! Thank you!
0

#6 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,184
  • Joined: 17-January 09
  • Location:Russia

Posted 23 December 2015 - 03:59 PM

Good catch, Bizley. Thanks!
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#7 User is offline   Bizley 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 922
  • Joined: 29-July 14
  • Location:Wrocław

Posted 23 December 2015 - 04:16 PM

Cheers.

You know @sven - this wouldn't happen with Yii 2 and namespaces :P
http://bizley.pl ʕ•ᴥ•ʔ
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users