把入口文件所有错误都打开,程序走services层就会报500

bug问题 · lynnwll · 于 6年前 发布 · 2062 次阅读

把入口文件的所有错误都打开,即把下面这句注释掉: error_reporting(E_ALL || ~E_NOTICE)

Undefined index: helper

 in D:\phpStudy\www\merchant\vendor\fancyecommerce\fecshop\services\Application.php at line 43
34353637383940414243444546474849505152

        $this->childService = $config;
    }
 
    /**
     * 得到services 里面配置的子服务childService的实例.
     * 单例模式,懒加载,使用的时候才会被实例化。类似于Yii2的component原理。
     */
    public function getChildService($childServiceName)
    {
        if (!$this->_childService[$childServiceName]) {
            $childService = $this->childService;
            if (isset($childService[$childServiceName])) {
                $service = $childService[$childServiceName];
                $this->_childService[$childServiceName] = Yii::createObject($service);
            } else {
                throw new InvalidConfigException('Child Service ['.$childServiceName.'] is not find in '.get_called_class().', you must config it! ');
            }
        }
 

2. in D:\phpStudy\www\merchant\vendor\fancyecommerce\fecshop\services\Application.php at line 43 – yii\base\ErrorHandler::handleError(8, 'Undefined index: helper', 'D:\phpStudy\www\merchant\vendor\...', 43, ...)
37383940414243444546474849

    /**
     * 得到services 里面配置的子服务childService的实例.
     * 单例模式,懒加载,使用的时候才会被实例化。类似于Yii2的component原理。
     */
    public function getChildService($childServiceName)
    {
        if (!$this->_childService[$childServiceName]) {
            $childService = $this->childService;
            if (isset($childService[$childServiceName])) {
                $service = $childService[$childServiceName];
                $this->_childService[$childServiceName] = Yii::createObject($service);
            } else {
                throw new InvalidConfigException('Child Service ['.$childServiceName.'] is not find in '.get_called_class().', you must config it! ');

3. in D:\phpStudy\www\merchant\vendor\fancyecommerce\fecshop\services\Application.php at line 62 – fecshop\services\Application::getChildService('helper')
565758596061626364

     * @property $attr | String , service的name。
     * 魔术方法,当调用一个属性,对象不存在的时候就会执行该方法,然后
     * 根据构造方法注入的配置,实例化service对象。
     */
    public function __get($attr)
    {
        return $this->getChildService($attr);
    }
}

4. in D:\phpStudy\www\merchant\vendor\fancyecommerce\fecshop\services\Service.php at line 87 – fecshop\services\Application::__get('helper')
81828384858687888990919293

 
    /**
     * 如果开启service log,则记录开始的时间。
     */
    protected function beginCall($originMethod, $arguments)
    {
        if (Yii::$service->helper->log->isServiceLogEnable()) {
            $this->_beginCallTime = microtime(true);
        }
    }
 
    /**
     * @param $originMethod and $arguments,魔术方法传递的参数

5. in D:\phpStudy\www\merchant\vendor\fancyecommerce\fecshop\services\Service.php at line 47 – fecshop\services\Service::beginCall('getUnderBranchId', [])
41424344454647484950515253

            $method = $this->_callFuncLog[$originMethod];
        } else {
            $method = 'action'.ucfirst($originMethod);
            $this->_callFuncLog[$originMethod] = $method;
        }
        if (method_exists($this, $method)) {
            $this->beginCall($originMethod, $arguments);
            $return = call_user_func_array([$this, $method], $arguments);
            $this->endCall($originMethod, $arguments);
 
            return $return;
        } else {
            throw new InvalidCallException('fecshop service method is not exit.  '.get_class($this)."::$method");

6. in D:\phpStudy\www\merchant\appcrm\modules\Crmbranch\block\index\Index.php at line 35 – fecshop\services\Service::__call('getUnderBranchId', [])
29303132333435363738394041

    public function getAll($params){
        $all = Yii::$service->Crmbranch->CBranch->getAll($params);
        return $all;
    }
    //分账号展示分支
    public function getUnderBranchId(){
        $data = Yii::$service->PublicMethod->getUnderBranchId();
        return $data;
    }
    //获取登录用户的branch_id
    public function getBranchUser(){
        $data = Yii::$service->BranchUser->getBranchUser();
        return $data;

7. in D:\phpStudy\www\merchant\appcrm\modules\Crmbranch\controllers\IndexController.php at line 28 – appcrm\modules\Crmbranch\block\index\Index::getUnderBranchId()
22232425262728293031323334

    public function actionIndex()
    {
        /**
         * 分账号展示分支,若无总分支,则需先添加总分支
         * 若有,返回分支id,中间以,隔开
         */
        $branchIdAll = $this->getBlock()->getUnderBranchId();
        if($branchIdAll == 'error'){
            Yii::$app->getSession()->setFlash('b_error', '无分支,请先添加总分支');
            return $this->redirect(['create']);
        }
        $arrIdAll = explode(',',$branchIdAll);
 

8. appcrm\modules\Crmbranch\controllers\IndexController::actionIndex()
9. in D:\phpStudy\www\merchant\vendor\yiisoft\yii2\base\InlineAction.php at line 57 – call_user_func_array([appcrm\modules\Crmbranch\controllers\IndexController, 'actionIndex'], [])
10. in D:\phpStudy\www\merchant\vendor\yiisoft\yii2\base\Controller.php at line 156 – yii\base\InlineAction::runWithParams([])
11. in D:\phpStudy\www\merchant\vendor\yiisoft\yii2\base\Module.php at line 523 – yii\base\Controller::runAction('index', [])
12. in D:\phpStudy\www\merchant\vendor\yiisoft\yii2\web\Application.php at line 102 – yii\base\Module::runAction('crmbranch/index/index', [])
13. in D:\phpStudy\www\merchant\vendor\yiisoft\yii2\base\Application.php at line 380 – yii\web\Application::handleRequest(yii\web\Request)
14. in D:\phpStudy\www\merchant\appcrm\web\index.php at line 58 – yii\base\Application::run()

除了屏蔽错误,还有别的解决办法吗?php版本是7.0

共收到 3 条回复
Fecmall#16年前 0 个赞

首先,并没有把错误全部关掉, error_reporting(E_ALL || ~E_NOTICE) 指的是显示除notice之前的所有error,

对于notice,譬如 数组key找不到,这也不是什么错误,这样需要把所有的数组调用都加上isset判断。

对于Yii2,是有内部错误报错机制,已经可以满足开发所需。

Fecmall#26年前 0 个赞

如果去掉这行代码,那么一个数组,

$arr = ['a' => 11, 'b' => 22]

调用了一个不存在key,譬如 $arr['ccc'] 就会报错。如果加上error_reporting(E_ALL || ~E_NOTICE),数组返回null,不需要做错误处理,如果去掉这行代码,任何一个数组的key的调用,都不需要加上isset判断。

3楼 已删除.
Fecmall#46年前 0 个赞

fecshop 就没有auth这个service Yii::$service->auth ,你自己造的services?

你自己造service ,好好看看这个文章:http://www.fecshop.com/doc/fecshop-guide/develop/cn-1.0/guide-fecshop-service-use.html

5楼 已删除.
添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics