Subject: Different results between PHP 5.6 and 7.0 with the fields from joined table
Hello, i have different results between PHP 5.6 and 7.0 with the fields from joined table. With PHP 5.6 the empty test is ok, but not with PHP 7.0 :
<?php // PHP 7.0.7 (Debian Stretch) $attributes = array( 'order' => 'id DESC', 'limit' => 25 ); $logs = Log::all($attributes); foreach ($logs as $log) { // $log->user->description = 'bla1'; $var = $log->user->description; // don't print if joined table ! if ( !empty($log->user->description) ) { print "A:{$log->user->description}"; } // print if $log->user->description is in $var if ( !empty($var) ) { print "B:{$log->user->description}"; } // $log->action = 'add'; // // print if field is not joined table if ( !empty($log->action) ) { print "Action:{$log->action}"; } } ?>
MySQL database :
CREATE TABLE IF NOT EXISTS `users` ( `id` INTEGER unsigned NOT NULL AUTO_INCREMENT, `login` VARCHAR(32) NOT NULL, `description` VARCHAR(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ; CREATE TABLE IF NOT EXISTS `logs` ( `id` INTEGER unsigned NOT NULL AUTO_INCREMENT, `user_id` INTEGER unsigned NOT NULL, `action` ENUM('add','change') DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ; INSERT INTO `users` (`id`, `login`, `description`) VALUES (1, 'fake1', 'bla1'), (2, 'fake2', NULL); INSERT INTO `logs` (`id`, `user_id`, `action`) VALUES (1, 1, 'add'), (1, 1, NULL);
PHP ActiveRecord models :
//User.php <?php class User extends ActiveRecord\Model { } ?>
//Log.php <?php class Log extends ActiveRecord\Model { static $belongs_to = array( array('user') ); } ?>
Thank you
June 27 2010
April 16, 2013
Subject: Different results between PHP 5.6 and 7.0 with the fields from joined table
Hello, i have different results between PHP 5.6 and 7.0 with the fields from joined table.
With PHP 5.6 the empty test is ok, but not with PHP 7.0 :
MySQL database :
PHP ActiveRecord models :
Thank you