System.out.print in PHP
March 9th, 2007 by Ivo
We are recruiting people on a regular basis, and since it's sometimes difficult to find people with both a computer science background and PHP experience, we also recruit people that are fluent in other languages. Teaching a c++/java/delphi-guy to do PHP in general is easier than teaching a PHP hobbyist good engineering practices.
So yesterday I was reviewing a code sample that a job applicant had written during a test and I encountered the following line of code:
It's not hard to guess what his background was , but I was initially stunned that this actually works in php.
My first thought was that this was because I installed the Java Bridge from Zend Platform, but the bridging API does not allow the direct use of java objects like this. So was there some evil hidden hack in PHP?
Of course not; eventually the truth was uncovered by the notices in the errorlog:
PHP Notice: Use of undefined constant System - assumed 'System'
Ah, that makes sense. It just sees them as constants which do not exist and are interpreted as strings, and apparently, this is a valid PHP statement as well:
I cannot find any practical use for being able to write a statement without assignment or output like that, but it does enable code beautification:
Of course I would have to strongly advise against this but it was fun to notice that this works.
P.S. shameless plug: this week we launched the first preview of our new web 2.0 pet project: http://www.mockatoo.com; not much to see just yet, but consider it a preview of what we are up to.