PHP命名空间无法在同一目录中的同一命名空间中查找类 - 在dev中工作,而不是prod

时间:2015-03-25 02:34:34

标签: php heroku namespaces yii2

我有以下PHP文件。它适用于开发。它们具有相同的命名空间和相同的PHP版本。当我部署到Heroku时,它会出错。你知道为什么吗?

Product.php
namespace app\models;
class Product extends \yii\db\ActiveRecord
public function getEbay()    {
    return $this->hasOne(Ebay::className(), ['product_id' => 'id'])->inverseOf('product'); # line 56
Ebay.php
namespace app\models;
class Ebay extends \yii\db\ActiveRecord
  

2015-03-25T02:00:01.003508 + 00:00 app [web.1]:[25-Mar-2015 02:00:01 UTC] PHP致命错误:类'app \ models \ Ebay'未找到在第56行的/app/models/Product.php

>heroku run php --version
Running `php --version` attached to terminal... up, run.5360
PHP 5.6.6 (cli) (built: Feb 19 2015 10:11:22)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies

本地:

$ php --version
PHP 5.6.6 (cli) (built: Feb 25 2015 13:54:50)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

好的,我甚至将use放在index.php中,但仍然失败。

C:\Users\Chloe\workspace\project>heroku run cat web/index.php
Running `cat web/index.php` attached to terminal... up, run.3679
<?php

// comment out the following two lines when deployed to production
if ($_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == '127.0.0.1') {
  defined('YII_DEBUG') or define('YII_DEBUG', true);
  defined('YII_ENV') or define('YII_ENV', 'dev');
}

require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

$config = require(__DIR__ . '/../config/web.php');

use app\models; Ebay::className();
(new yii\web\Application($config))->run();

C:\Users\Chloe\workspace\project>heroku logs
...
2015-03-26T17:10:13.590855+00:00 app[web.1]: [26-Mar-2015 17:10:13 UTC] PHP Fatal error:  Class 'Ebay' not found in /app/web/index.php on line 14

1 个答案:

答案 0 :(得分:1)

好的,我找到了。这是因为该文件在Git和Heroku中被命名为EBay.php,而在Windows文件系统中被命名为Ebay.php。诅咒你Git!这解决了它。

git mv -f models/EBay.php models/Ebay.php

此命令失败,因此我不得不进一步调查:

heroku run ls models/Ebay.php