Title: Learning PHP + a small WIP PHP5 Manual
Slug: learning-php-a-small-wip-php5-manual
Date: 2009-02-09 04:10:00
Author: Kartones
Lang: en
Tags: Development, PHP, C#
Description: Exploring PHP.

 <p>One of the interviews I'm currently doing <a href="https://blog.kartones.net/post/i-m-getting-fired/">to search for a new job</a> is for developing with PHP/MySQL/Linux. </p>  <p>While this could seem shocking at first (just looking at the tag cloud on the right of the blog anyone can see I'm a .NET developer), it's not the first time I switch from languages (I've professionally worked with VB6, ASP 3, VB.NET, C#, ASP.NET and a bit of C++), and the company seems interested on me (mostly because I would have to learn almost from scratch).</p>  <p>But apart from having multiple interviews, <a>it was logical</a> to perform a code test. I did it yesterday (via email, sent two hours later as complete as possible in so tight timeline), and although I have yet much PHP to learn, I can start to make an oppinion of it.</p>  <p> </p>  <p>PHP is not bad, in fact I had fun developing with it, it just suffers the "Visual Basic syndrome<span style="line-height: 1.428571429;">"</span><span style="line-height: 1.428571429;">: in the past was so bad that has legacy problems and bad habits, and some features that need further improvement.</span></p>  <p> </p>  <p>Object orientation of the language is ok, far from .NET but allows a lot of stuff. The biggest problem is the absence of namespaces concept, which leads to either awful class naming with underscores or having to take extra caution when deciding classnames.</p>  <p>But the inherited bad old stuff allows things like this:</p>  <p><font face="Courier New">class SampleClass     <br>{      <br>    public $name = "";      <br>}      <br>      <br>$myClass = new SampleClass();      <br>$myClass-&gt;namee = "Kartones";    // typo here on purpose</font></p>  <p>Guess what happens? "namee" is added on-the-fly to myClass object!!! Dynamic property creation should be at the very least restricted!</p>  <p> </p>  <p>The syntax is a bit strange, and has some "exceptions", like this example:</p>  <p><font face="Courier New">$this-&gt;myProperty = 5;    // Access current instance property     <br>self::$staticProperty = 5;    // Access a static property      <br>$this-&gt;subObject-&gt;subObjProperty = 5;    // Access a object property's property      <br>parent::subObject-&gt;subObjPropert = 5;    // Access parent class object property's property</font></p>  <p>Clear, uh? the use of "<font face="Courier New">::</font>" is supposed to be for static methods/properties, and "<font face="Courier New">-&gt;</font>" for instance ones, but then "<font face="Courier New">::</font>" is used too to access base class <b>instance</b> :P</p>  <p> </p>  <p>But apart from that, it is interesting and once you know those delicate things, is not hard to develop with it. I've spent three days and done some small stuff (like implementing a few design patterns or manipulating images).</p>  <p>I don't discard doing something combining .NET (for the BLL/DAL part) and PHP (for the "presentation layer") to see how they work together.</p>  <p>The 5.2.8 version runs fine as a ISAPI filter under IIS (tested on 5.1 IIS), and all the code was written with Notepad2 (like the Windows original one but with syntax highlighting). Just make sure to read both <a href="http://www.php.net/manual/en/install.windows.manual.php">the manual installation instructions</a> AND the comments (I forgot to add a system variable to PHP's path and it was getting a "default configuration" instead of the correct PHP.ini one!).</p>  <p> </p>  <p>Finally, as one of my habits at university, I've started writing a small PHP manual (oriented to C# devs.). I plan to update it as I go along learning more PHP.</p>  <p>The latest version of the manual <strike>can be found here</strike> (removed, never got to finish it).
