{"id":570,"date":"2007-08-11T12:34:54","date_gmt":"2007-08-11T19:34:54","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/2007\/08\/11\/check-if-your-phps-diff-syntax-isnt-breaking\/"},"modified":"2007-08-11T12:34:54","modified_gmt":"2007-08-11T19:34:54","slug":"check-if-your-phps-diff-syntax-isnt-breaking","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/check-if-your-phps-diff-syntax-isnt-breaking\/","title":{"rendered":"Check if your PHP&#8217;s diff syntax isn&#8217;t breaking"},"content":{"rendered":"<p>Say you&#8217;re working on emacs, without any kind of syntax checking, and you don&#8217;t want to commit your code cause you might have syntax errors.<\/p>\n<p>If you&#8217;re smart, the best way to know what files you actually changed, is using <\/p>\n<pre>\nsvn diff | grep +++\n<\/pre>\n<p>(that is, if you&#8217;re using subversion, which I hope you are)<\/p>\n<p>then you&#8217;d have to do, <\/p>\n<pre>\nphp -l <file>\n<\/pre>\n<p>on each one of the files&#8230;<\/p>\n<p>well, that looks like a script to me.<\/p>\n<p>Add the following script to your path, name it&#8230; checkdiffsyntax<\/p>\n<pre>\n#!\/bin\/bash\n\n#Put all the files that changed on a temp file and then dump them into a MYBLOOP_DIFF_FILES variable\nTMP_FILE=\/tmp\/changed_${USER}\nsvn diff | grep +++ | awk {'print $2'} > ${TMP_FILE}; export MYBLOOP_DIFF_FILES=`cat ${TMP_FILE}`\n\nfor file in $MYBLOOP_DIFF_FILES\ndo\n  php -l $file\ndone\n\nrm ${TMP_FILE}\n<\/pre>\n<p><strong>UPDATE<\/strong><br \/>\nI learn how to use <strong>for<\/strong> as a one liner on bash, and also how to do this without dumping the filepaths to a file which gets fed into a string&#8230; now it just goes straight from awk into the for loop, sick. I will leave the example above for future reference in case you need how to put the contents of a file on a variable and then reading from them<\/p>\n<p>New script looks like this now, one liner.<\/p>\n<pre>\nsvn diff | grep +++ | for file in `awk {'print $2'}`; do echo ${file}; php -l ${file}; done\n<\/pre>\n<p>chmod 777 it, and you&#8217;re ready to go.<\/p>\n<p>Should look like this when you run it<\/p>\n<pre>\nangel@foobar:~\/public_html$ checkdiffsyntax\nNo syntax errors detected in members\/ajax\/mashup.php\nNo syntax errors detected in foo\/mashups\/twitter\/twitter.php\nNo syntax errors detected in foo\/classes\/utils.php\nNo syntax errors detected in foo\/classes\/user.php\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Say you&#8217;re working on emacs, without any kind of syntax checking, and you don&#8217;t want to commit your code cause you might have syntax errors. If you&#8217;re smart, the best way to know what files you actually changed, is using svn diff | grep +++ (that is, if you&#8217;re using subversion, which I hope you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_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},"jetpack_post_was_ever_published":false},"categories":[15,30,43],"tags":[],"class_list":["post-570","post","type-post","status-publish","format-standard","hentry","category-code","category-geeklife","category-linux"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-9c","jetpack-related-posts":[{"id":513,"url":"https:\/\/www.gubatron.com\/blog\/bash-alias-svn_diff_counter-count-lines-added-and-removed\/","url_meta":{"origin":570,"position":0},"title":"Bash Alias &#8211; &#8220;svn_diff_counter&#8221;: Count lines added and removed","author":"gubatron","date":"April 30, 2007","format":false,"excerpt":"I love to know how many lines I've added and deleted before making a commit. This is why I created this alias: alias svn_diff_counter='svn diff | egrep \"^[+|-].*\" | egrep -v \"(+++)|(---)\" > .tmp_diff_counter ; added=`egrep \"(^+)\" .tmp_diff_counter | wc -l`; removed=`egrep \"(^-)\" .tmp_diff_counter | wc -l`; rm .tmp_diff_counter; echo\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2087,"url":"https:\/\/www.gubatron.com\/blog\/mercurial-for-subversion-expats-merging-remote-changes-abort-push-creates-new-remote-heads\/","url_meta":{"origin":570,"position":1},"title":"Mercurial for Subversion Expats: Merging remote changes. &#8220;abort: push creates new remote heads!&#8221;","author":"gubatron","date":"November 14, 2010","format":false,"excerpt":"Commit anywhere\/anytime with Mercurial So you have been using subversion for the past few years and now your team has decided to move on to Mercurial for all the benefits. Two or more people are working on the same branch and they're pushing code to the main copy of the\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":582,"url":"https:\/\/www.gubatron.com\/blog\/linuxcomo-copiar-un-archivo-a-multiples-ubicaciones-con-un-solo-comando\/","url_meta":{"origin":570,"position":2},"title":"Linux: Como copiar un archivo a multiples ubicaciones con un solo comando","author":"gubatron","date":"August 29, 2007","format":false,"excerpt":"Aprovecho la ocasion para ilustrar un poco el poder del bash a los amigos que recien se unen al mundo de linux. Muchas veces tienes que hacer operaciones en las cuales tienes que tocar multiples archivos, por ejemplo, remplazar un archivo en varios lugares. Yendo a un ejemplo concreto, El\u2026","rel":"","context":"In &quot;Geeklife&quot;","block_context":{"text":"Geeklife","link":"https:\/\/www.gubatron.com\/blog\/category\/geeklife\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2749,"url":"https:\/\/www.gubatron.com\/blog\/deploying-html5-apps-on-cloudfront-with-efficient-invalidation-requests\/","url_meta":{"origin":570,"position":3},"title":"Deploying HTML5 apps on CloudFront with efficient invalidation requests","author":"gubatron","date":"June 8, 2012","format":false,"excerpt":"So you decided to build your next web app\/site using nothing but HTML5 and Javascript. No server side processing for anything related to UI. This means you will be coding a lot of JavaScript. Wouldn't it be nice to put all that static HTML and JS on your CloudFront CDN\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":63,"url":"https:\/\/www.gubatron.com\/blog\/vaciando-el-buffer\/","url_meta":{"origin":570,"position":4},"title":"Vaciando el Buffer","author":"gubatron","date":"December 10, 2004","format":false,"excerpt":"Este post es un poco para desahogar algunos consejos y tips que he querido tener anotados, y que mejor lugar que el blog, donde mis notas personales pueden ayudar a otros. En mi \u00faltimas asignaciones profesionales he tenido que trabajar en ambientes 100% Linux, esto me ha hecho refrescar viejas\u2026","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1457,"url":"https:\/\/www.gubatron.com\/blog\/map-commands-to-servers-via-ssh\/","url_meta":{"origin":570,"position":5},"title":"Quick N Dirty way to Map Commands to remote servers via ssh","author":"gubatron","date":"October 10, 2009","format":false,"excerpt":"You may be running several independent but similar servers at the same time and wasting time by executing commands in all of them one by one. Wouldn't it be nice to send a command to all of them at once? or to monitor all of them at once. The following\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=570"}],"version-history":[{"count":0,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/570\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}