{"id":369,"date":"2009-06-07T16:46:56","date_gmt":"2009-06-07T23:46:56","guid":{"rendered":"http:\/\/www.evardsson.com\/blog\/?p=369"},"modified":"2009-06-07T16:46:56","modified_gmt":"2009-06-07T23:46:56","slug":"error-handling-and-the-php-operator","status":"publish","type":"post","link":"https:\/\/www.evardsson.com\/blog\/2009\/06\/07\/error-handling-and-the-php-operator\/","title":{"rendered":"Error Handling and the PHP @ Operator"},"content":{"rendered":"<p>I have been trying to debug a plugin for WordPress (<a href=\"http:\/\/www.samuelaguilera.com\/archivo\/shorten2ping-notifies-pingfm-bitly.xhtml\">Shorten2Ping<\/a> &#8211; I will keep plugging this because I think it is so nifty!) and I was running into a problem where the plugin would silently fail with nothing in the logs, no error printing to screen, just dead silence.<\/p>\n<p>I turned on display_errors in php.ini for a while to see if anything would show up. Still nothing. So I started to look through the file again. I knew it was getting as far as creating the short url in <a href=\"http:\/\/bit.ly\">bit.ly<\/a> before it died, but nothing was getting entered into the database. So I started through the <code>make_bitly_url()<\/code> function and what jumped out and slapped me in the face? <code>$json = @json_decode($response,true);<\/code> That little, innocuous-looking @ was gulping the error message from a fatal error! (Namely, &#8220;<code>Call to undefined function json_decode()<\/code>&#8220;). It turns out that I had PHP compiled with &#8211;disable-json, which is default for Gentoo <em>unless<\/em> you have json in your USE flags.<\/p>\n<p>According to the PHP docs for the Error Control Operator @:<\/p>\n<blockquote>\n<p id=\"line78\">Currently the &#8220;@&#8221; error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use &#8220;@&#8221; to suppress errors from a certain function and either it isn&#8217;t available or has been mistyped, the script will die right there with no indication as to why.<\/p>\n<\/blockquote>\n<p>So, if you really must supress error messages, do so, but do so with care. In the case where a suppressed error may be fatal (as in this case) be sure to add documentation to that effect. As in &#8220;If this dies a silent death it may very well be that you do not have function xyz() enabled.&#8221;<\/p>\n<p>And, note to self, when debugging PHP, the first thing to do is look for and remove the error control operator.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been trying to debug a plugin for WordPress (Shorten2Ping &#8211; I will keep plugging this because I think it is so nifty!) and I was running into a problem where the plugin would &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11,33],"tags":[99,170],"class_list":["post-369","post","type-post","status-publish","format-standard","hentry","category-development","category-php","tag-debugging","tag-php"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pxT7i-5X","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts\/369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/comments?post=369"}],"version-history":[{"count":1,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts\/369\/revisions"}],"predecessor-version":[{"id":370,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/posts\/369\/revisions\/370"}],"wp:attachment":[{"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/media?parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/categories?post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.evardsson.com\/blog\/wp-json\/wp\/v2\/tags?post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}