{"id":1537,"date":"2022-08-30T15:17:21","date_gmt":"2022-08-30T15:17:21","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/how-to-automatically-handle-all-unhandled-php-errors-in-symfony2-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:21","modified_gmt":"2022-08-30T15:17:21","slug":"how-to-automatically-handle-all-unhandled-php-errors-in-symfony2-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-automatically-handle-all-unhandled-php-errors-in-symfony2-collection-of-common-programming-errors\/","title":{"rendered":"How to automatically handle all unhandled php errors in symfony2?-Collection of common programming errors"},"content":{"rendered":"<p>Disclaimer:<\/p>\n<p>seems like you guys need some real world example for that. So here it is:<\/p>\n<pre><code>file_get_contents($filename);\n<\/code><\/pre>\n<p>Keep in mind about thread safety and race conditions.<\/p>\n<p>or any other php notice\/warning or any kind of recoverable exception.<\/p>\n<p>where either is not defined. And run it in the default <code>app.php<\/code> with all the default symfony v2.3.5 configs &#8211; I see<\/p>\n<pre><code>Notice: Undefined variable: i in \/var\/www\/...\/UIBundle\/Controller\/DeployController.php on line 57\n\nCall Stack:\n    0.0000     629696   1. {main}() \/var\/www\/...\/web\/app.php:0\n<\/code><\/pre>\n<p>Which is not what I expect since in the production mode framework should handle everything, log and show a nice 404\/500 to a user.<\/p>\n<p>What am I missing and what config parameter should change the behaviour to what I expect?<\/p>\n<p><strong>UPD<\/strong>:<\/p>\n<p>this question is about how to handle unhandled php errors so that user didn&#8217;t see the stacktrace but a proper error page on production. So treat <code>$i++<\/code> and <code>\\bla()<\/code> as some unexpected case, a bug.<\/p>\n<p><strong>UPD 2<\/strong>:<\/p>\n<p>yes, I&#8217;m aware of the <code>debug<\/code> parameter of the <code>Kernel<\/code> class, and personally I don&#8217;t see switching to<\/p>\n<pre><code>$kernel = new AppKernel('prod', true);\n                                 ^--- changed from false\n<\/code><\/pre>\n<p>reasonable, since I need a <em>real<\/em> production environment.<\/p>\n<p><strong>UPD 3<\/strong>:<\/p>\n<p>Guys, I&#8217;m aware what unit, functional, acceptance and integration tests are for. The question <strong>IS NOT<\/strong> about testing. The question is: how to handle php errors by symfony2 natively.<\/p>\n<p><strong>UPD 4<\/strong>:<\/p>\n<p>The question is about the latest symfony2 branch &#8211; 2.3 (or v2.3.5 specifically)<\/p>\n<p><strong>UPD 5<\/strong>:<\/p>\n<p><code>Debug::enable(null, false);<\/code> &#8211; could please someone comment a possible negative side effects if I used this in production? &#8212; it doesn&#8217;t log notices\/warnings :-S<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-27 05:07:44. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Disclaimer: seems like you guys need some real world example for that. So here it is: file_get_contents($filename); Keep in mind about thread safety and race conditions. or any other php notice\/warning or any kind of recoverable exception. where either is not defined. And run it in the default app.php with all the default symfony v2.3.5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1537","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1537"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1537\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}