laravel3列表中的匿名函数无法在a2hosting的php中运行,在本地php中运行良好

时间:2013-08-01 22:30:07

标签: php hosting closures anonymous-function laravel-3

在a2hosting中,当我运行artisan migration时,我收到了以下错误消息:

Notice: Trying to get property of non-object in /home/letsmaka/letsmakan/laravel/database/query.php on line 677

迁移无法运行,因为它尝试执行已经运行的迁移。此错误还会影响使用雄辩关系方法的Web应用程序。

我创建了一个简单的任务来测试这个错误:

class Test_Query_Lists_Task {

  public function run($arguments)
  {
    print_r( DB::table('laravel_migrations')->where_bundle('application')->lists('name') );
  }

}

以下是我当地笔记本电脑的结果:

$ php artisan test_query_lists
Array
(
    [0] => 2012_12_30_170932_create_session_table
    [1] => 2013_01_20_014710_create_users_table
    [2] => 2013_01_20_014725_create_restaurants_table
    [3] => 2013_01_20_093320_create_reviews_table
    [4] => 2013_01_20_093329_create_menus_table
    [5] => 2013_01_20_093410_create_taxonomies_table
    [6] => 2013_02_08_005320_create_restaurant_taxonomy_table
    [7] => 2013_03_30_161928_staple_restaurants_table
    [8] => 2013_04_01_083523_staple_users_table
    [9] => 2013_04_05_101718_add_column_to_restaurants_table
    [10] => 2013_04_05_151456_create_landmarks_table
    [11] => 2013_04_08_220234_create_restaurants_associations_tables
    [12] => 2013_04_08_225949_create_review_comments_table
    [13] => 2013_04_08_230243_create_badges_table
    [14] => 2013_04_08_230613_create_guides_table
    [15] => 2013_04_08_231201_create_restaurant_photos_table
    [16] => 2013_04_10_122201_fix_relation
    [17] => 2013_04_15_193712_add_cities_table
    [18] => 2013_04_23_070312_add_provinces
    [19] => 2013_04_25_230524_add_province_and_city_foreign_keys
    [20] => 2013_05_05_010828_create_pages_table
    [21] => 2013_05_05_151440_add_en_column_to_page
    [22] => 2013_05_11_215824_add_navigations_table
    [23] => 2013_05_11_220719_fix_related_pages_table
    [24] => 2013_05_11_230543_add_tag_to_navigations
    [25] => 2013_05_12_105057_rename_navigation_to_link
    [26] => 2013_05_14_175304_add_business_owner
    [27] => 2013_05_15_184403_add_timezone_to_users_table
    [28] => 2013_05_19_172729_add_user_id_to_restaurant_photo
    [29] => 2013_06_16_075032_add_authentications_table
    [30] => 2013_06_17_121416_add_uid_to_authentications_table
    [31] => 2013_06_22_035428_add_photo_description_to_restaurant_photos
    [32] => 2013_06_22_085548_add_is_approved_to_restaurant_photos
    [33] => 2013_06_23_193459_add_fields_to_users_table
    [34] => 2013_06_25_084751_add_is_approved_to_review
    [35] => 2013_06_25_101550_add_spam_mark_to_reviews
    [36] => 2013_06_25_105936_add_slug_to_restaurants
    [37] => 2013_06_25_123441_add_picture_to_menus
    [38] => 2013_06_25_124645_staple_guides_table
    [39] => 2013_06_25_125905_add_user_id_to_guide
    [40] => 2013_06_25_142312_staple_guides_table
    [41] => 2013_06_25_143651_staple_menus_table
    [42] => 2013_06_25_150150_add_like_count_to_restaurants
    [43] => 2013_06_27_153034_staple_taxonomies_table
    [44] => 2013_06_28_162745_create_ip2location_db5s_table
    [45] => 2013_06_28_203807_add_region_name_to_provinces_table
    [46] => 2013_07_01_164548_add_slug_to_guides
    [47] => 2013_07_01_233517_add_like_count_to_guides
    [48] => 2013_07_14_073249_add_province_and_city_to_users
    [49] => 2013_07_18_072923_add_likes_table
    [50] => 2013_07_18_132939_add_glike_table
)

这是a2hosting的结果:

$ php artisan test_query_lists --env=beta
Array
(
    [0] => 
    [1] => 
    [2] => 
    [3] => 
    [4] => 
    [5] => 
    [6] => 
    [7] => 
    [8] => 
    [9] => 
    [10] => 
    [11] => 
    [12] => 
    [13] => 
    [14] => 
    [15] => 
    [16] => 
    [17] => 
    [18] => 
    [19] => 
    [20] => 
    [21] => 
    [22] => 
    [23] => 
    [24] => 
    [25] => 
    [26] => 
    [27] => 
    [28] => 
    [29] => 
    [30] => 
    [31] => 
    [32] => 
    [33] => 
    [34] => 
    [35] => 
    [36] => 
    [37] => 
    [38] => 
    [39] => 
    [40] => 
    [41] => 
    [42] => 
    [43] => 
    [44] => 
    [45] => 
    [46] => 
    [47] => 
    [48] => 
    [49] => 
)

使用php 5.4时:

$ php5.4 artisan test_query_lists --env=beta
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
PHP Notice:  Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677

Notice: Trying to get property of non-object in /home/letsmaka/beta/laravel/database/query.php on line 677
Array
(
    [0] => 
    [1] => 
    [2] => 
    [3] => 
    [4] => 
    [5] => 
    [6] => 
    [7] => 
    [8] => 
    [9] => 
    [10] => 
    [11] => 
    [12] => 
    [13] => 
    [14] => 
    [15] => 
    [16] => 
    [17] => 
    [18] => 
    [19] => 
    [20] => 
    [21] => 
    [22] => 
    [23] => 
    [24] => 
    [25] => 
    [26] => 
    [27] => 
    [28] => 
    [29] => 
    [30] => 
    [31] => 
    [32] => 
    [33] => 
    [34] => 
    [35] => 
    [36] => 
    [37] => 
    [38] => 
    [39] => 
    [40] => 
    [41] => 
    [42] => 
    [43] => 
    [44] => 
    [45] => 
    [46] => 
    [47] => 
    [48] => 
    [49] => 
)

我本地的php版本:

$ php -v
PHP 5.4.6-1ubuntu1.3 (cli) (built: Jul 15 2013 18:19:45) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

在a2hosting中:

$ php -v
PHP 5.3.23 (cli) (built: Apr 23 2013 11:28:59) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
    with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd., and
    with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies

$ php5.4 --version
PHP 5.4.13 (cli) (built: Apr 22 2013 17:57:38) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

以下是lists

query.php方法的摘要
/**
 * Get an array with the values of a given column.
 *
 * @param  string  $column
 * @param  string  $key
 * @return array
 */
public function lists($column, $key = null)
{
  $columns = (is_null($key)) ? array($column) : array($column, $key);

  $results = $this->get($columns);

  // First we will get the array of values for the requested column.
  // Of course, this array will simply have numeric keys. After we
  // have this array we will determine if we need to key the array
  // by another column from the result set.
  $values = array_map(function($row) use ($column)
  {
    return $row->$column;

  }, $results);

  // If a key was provided, we will extract an array of keys and
  // set the keys on the array of values using the array_combine
  // function provided by PHP, which should give us the proper
  // array form to return from the method.
  if ( ! is_null($key) && count($results))
  {
    return array_combine(array_map(function($row) use ($key)
    {
      return $row->$key;

    }, $results), $values);
  }

  return $values;
}

第677行是这段代码: return $row->$column;

刚刚开始的错误发生在过去几周。在此之前,所有迁移都成功运行而没有错误。

为什么list方法使用的匿名函数无法运行?需要在php中启用哪些设置才能使其正常工作?

感谢。

更新

我尝试通过添加以下内容来调试此问题:

675     $values = array_map(function($row) use ($column)
676     {
677       print_r($row);
678       return $row->$column;
679     
680     }, $results);

在我当地,我得到了这个:

stdClass Object
(
    [name] => 2012_12_30_170932_create_session_table
)

但在a2hosting中,我得到了这个:

Array
(   
    [name] => 2012_12_30_170932_create_session_table
    [0] => 2012_12_30_170932_create_session_table
)

为什么php行为变得不同以及如何让它像其他标准的php一样?

1 个答案:

答案 0 :(得分:0)

通过将fetch设置添加到数据库设置,现在laravel数据库类的行为在整个平台上是相同的:

/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may wish to retrieve records as arrays
| instead of objects. Here you can control the PDO fetch style of the
| database queries run by your application.
|
*/

'fetch' => PDO::FETCH_CLASS,