php - 为什么在电子邮件中传递 LINUX 命令时我的 catch block 不起作用?

标签 php linux zend-framework2 try-catch

我有一些看起来像这样的代码

  try
  {
    $emailObj->checkEmailExist($emailid);
  }
  catch(Exception $e)
  {
    echo 'Insert Record.';
    $emailObj->addEmail($emailid);
  }

  static function checkEmailExist($emailID)
  {
    $rowset = $this->_tableGateway->select(array('user_email_id'=>$emailID));
    $row = $rowset->current();
  }
  if (!$row) {
    throw new \Exception("Could not find data for email : $emailID",404);
  }     
  return $row;
}

现在,当我传递包含任何 LINUX 命令(如 scp、rcp、ssh)的电子邮件时,catch block 不会执行

如果我像这样传递电子邮件

  • test@gmail.com

it check if exist or not, if not then insert email

如果我像这样传递电子邮件

  • ssh.test@gmail.com

it stops execution with throw an exception, even email not exist - Insert function not executed.

我不确定为什么 catch block 无法在电子邮件中使用 LINUX 命令? 请帮助...

最佳答案

我想你的类可能是命名空间的,如果是这样你需要根除你正在捕获的异常类:

try
{
     $emailObj->checkEmailExist($emailid);
}
catch(\Exception $e)
{
    echo 'Insert Record.';
    $emailObj->addEmail($emailid);
}

通过在其前面添加\,或者默认查找namespace\Exception

我只是根据你抛出异常的方式来猜测

throw new \Exception("Could not find data for email : $emailID",404);

如果您的类没有命名空间,则不需要使用 \Exception。您可以改为执行 Exception

干杯!

最后一件事,您输入的代码完全无效:

  try{ 
   ...
  }

  static function checkEmailExist(){
  ...
  }

这对我来说是这样的:

 <?php
   namespace somename;
  class someclass{


        try{ 
         ...
        }

        static function checkEmailExist(){
        ...
        }


 }

在什么地方你不能把那个 try block 放在那里。但也许事实并非如此,您发布的只是一种简化?

关于php - 为什么在电子邮件中传递 LINUX 命令时我的 catch block 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39609694/

相关文章:

linux - x86 汇编语言 : Shift multiplication with 64 bit answer

php - Zend Framework 2 结果集按条件排序?

php - gdb 显示奇怪的无符号线程导致 SIGSEGV - 它是什么?

php - 没有返回结果的sql

php - 无法让 php 在 ubuntu 上运行

php - jquery Autocomplete 使用旧版本的浏览器而不是新版本的浏览器?

linux - 如何让Linux上的 `write()`系统调用立即生效?

backbone.js - PHP ZF2 - Restful Controller Backbone PUT 方法解析不正确

php - Zend Framework 2 记录到 MySQL DB 附加列插入空

php - 如果钱包中没有私钥,如何检查 0 确认比特币交易?