[英]PHP namespace not finding class in same namespace in same directory - works in dev, not prod
I have the following PHP files. 我有以下PHP文件。 It works in dev.
它可以在开发人员中使用。 They have the same namespace, and same PHP version.
它们具有相同的名称空间和相同的PHP版本。 When I deploy to Heroku, it gives an error.
当我部署到Heroku时,出现错误。 Do you know why?
你知道为什么吗?
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 Fatal error: Class 'app\\models\\Ebay' not found in /app/models/Product.php on line 56
2015-03-25T02:00:01.003508 + 00:00 app [web.1]:[2015年3月25日02:00:01 UTC] PHP致命错误:在/ app中找不到类'app \\ models \\ Ebay' /models/Product.php,第56行
>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
Local: 本地:
$ 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
Ok I even put the use
in the index.php
and it still fails. 好吧,我甚至把
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
Ok I found it. 好的,我找到了。 It was because the file was named
EBay.php
in Git and Heroku but Ebay.php
on the Windows file system. 这是因为该文件被命名为
EBay.php
在Git和Heroku的,但Ebay.php
Windows文件系统上。 Curse you Git! 诅咒你,Git! This solved it.
这解决了。
git mv -f models/EBay.php models/Ebay.php
This command failed so I had to investigate further: 该命令失败,因此我不得不进一步调查:
heroku run ls models/Ebay.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.