2013-08-01 24 views
0

在a2hosting,當我運行工匠遷移,我得到這個錯誤信息:匿名函數未能在a2hosting的PHP運行在本地運行PHP以及

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中啓用哪些設置才能使其工作?

謝謝。

UPDATE

我嘗試調試這個問題,通過補充一點:

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?

回答

0

通過增加取指令設置爲數據庫設置,現在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,