草庐IT

Catch-All

全部标签

php - Laravel 保存($request->all()) 错误

我有一个问题,我一直在开发laravel应用程序,我遇到了这个奇怪的错误:QueryExceptioninConnection.phpline770:SQLSTATE[23000]:Integrityconstraintviolation:1452Cannotaddorupdateachildrow:aforeignkeyconstraintfails(`testenv`.`products`,CONSTRAINT`products_tenant_id_foreign`FOREIGNKEY(`tenant_id`)REFERENCES`tenants`(`id`))(SQL:inser

php - 为什么 preg_match_all() 会多次创建相同的答案?

以下代码从推文中提取#hashtags并将它们放入变量$matches中。$tweet="thishasa#hashtaga#badhash-taganda#goodhash_tag";preg_match_all("/(#\w+)/",$tweet,$matches);var_dump($matches);有人可以向我解释为什么以下结果有2个相同的数组,而不是只有1个吗?array(2){[0]=>array(3){[0]=>string(8)"#hashtag"[1]=>string(8)"#badhash"[2]=>string(13)"#goodhash_tag"}[1]=>a

php - 我可以在将 html 文件加载到 DOMDocument 时 try catch PHP 警告吗?

是否有可能进行某种trycatch来捕获警告?例如if(!$dom->loadHTMLFile($url)){//ifcantloadfilehandleerrormyway}对于我正在使用的$urlWarning(2):DOMDocument::loadHTMLFile(MYURL)[domdocument.loadhtmlfile]:failedtoopenstream:HTTPrequestfailed!HTTP/1.0403Forbidden[APP\controllers\import_controller.php,line62]Warning(2):DOMDocument:

PHP - try/catch 的开销是否高于 if/then?

在处理一些遗留代码时,我遇到了大量的Try/Catch语句。Try/Catch不是他们在我的Zend认证类(class)中教授的东西,而且10年来我没有与使用它的其他PHP开发人员一起工作。与执行if语句相比,Try/Catch是否有额外的开销?是什么让它比其他选择更受欢迎或更不受欢迎? 最佳答案 我不认为它们彼此真正相关。If语句用于确定分支逻辑。Try/Catch是处理发生的错误。可以在Catchblock中处理会使程序停止的异常。 关于PHP-try/catch的开销是否高于if/

php - try catch laravel 不适用于重复输入

我在LaravelController中使用以下代码。并得到username的重复错误,但我需要通过try-catch来处理它。此代码无效。insert(['username'=>$request->username,'phone'=>$request->phone,'status'=>1]);}catch(Exception$exception){$errormsg='Databaseerror!'.$exception->getCode();}returnResponse::json(['success'=>$result,'errormsg'=>$errormsg]);}}我遇到

php - 发送 : How to add webpage title in all my views?

现在我必须像这样分别在我的所有View中添加标题:TestProject-Home和TestProject-Dashboard现在,如果我想更改标题的TestProject部分,那么我必须在所有View中更改它。我如何在BootStrap.php中提及它并将其添加到所有View中?每当我必须更改它时,我都会在一个地方更改它。 最佳答案 您应该查看headTitleView助手。您可以将此代码段放在您的Bootstrap文件中(来自http://framework.zend.com/manual/en/zend.view.helper

regex - PHP preg_match_all 限制

我将preg_match_all用于非常长的模式。当运行代码时,我得到了这个错误:Warning:preg_match_all():Compilationfailed:regularexpressionistoolargeatoffset707830经过搜索,我得到了解决方案,所以我应该增加php.ini中的pcre.backtrack_limit和pcre.recursion_limit的值>/p>但是在我增加值并重新启动我的apache之后,它仍然遇到同样的问题。我的PHP版本是5.3.8 最佳答案 该错误与正则表达式的性能无关

php - Zend/PHP : How to remove all leading 0s from string?

我有一个只包含数字的字符串。现在我想从该字符串中删除所有前导0例如:input:000000001230output:1230input:01000output:1000在PHP/Zend中有这方面的功能吗?谢谢 最佳答案 $myvar=ltrim('01000','0'); 关于php-Zend/PHP:Howtoremoveallleading0sfromstring?,我们在StackOverflow上找到一个类似的问题: https://stackov

php - catch 不工作

我很困惑。是什么导致“catch”无法正常工作?我该如何解决?getMessage());}?>实际输出[27-Apr-201009:43:24]PHPFatalerror:Uncaughtexception'Exception'withmessage'BOOM'in/mycode/exception_problem/index.php:4Stacktrace:#0{main}thrownin/mycode/exception_problem/index.phponline4期望的输出shouldhappen:BOOMPHP版本5.2.3在php_info()中,我没有看到任何可以禁用

php - 如何处理其他 try catch block 中的异常?

我的例子:classCustomExceptionextends\Exception{}classFirstClass{functionmethod(){try{$get=external();if(!isset($get['ok'])){thrownewCustomException;}return$get;}catch(Exception$ex){echo'ERROR1';die();}}}classSecondClass{functionget(){try{$firstClass=newFirstClass();$get=$firstClass->method();}catch(