{"id":175,"date":"2007-04-01T13:03:50","date_gmt":"2007-04-01T12:03:50","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/?p=175"},"modified":"2007-04-01T13:03:50","modified_gmt":"2007-04-01T12:03:50","slug":"delphi-for-php-first-impressions","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/175-delphi-for-php-first-impressions.html","title":{"rendered":"Delphi for PHP first impressions"},"content":{"rendered":"<p>I tried out Delphi for PHP for the first time this weekend.<\/p>\n<p>Install on Vista was smooth. The setup installs its own copy of Apache 2 and PHP 5. A few minutes later and I was up and running.<\/p>\n<p>The IDE is Delphi-like. Here is a scrunched-up image to give you a flavour:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.itwriting.com\/images\/delphiphpsm.gif\">&nbsp;<\/p>\n<p>I have a standard application I build when trying out a new development tool. It is a to-do list with a listbox, a textbox, and buttons to add and remove items from the list. I started well, and soon had the controls placed, though they are tricky to line-up nicely. I resorted to setting the Left property as the snap-to-grid did not work for me.<\/p>\n<p>Then I double-clicked the Add button. As expected, I was greeted with an empty Click handler. What to type? After a little experimentation I came up with this:<\/p>\n<blockquote>\n<p>$this-&gt;lstItems-&gt;AddItem($this-&gt;ebItem-&gt;Text,null,null); <\/p>\n<\/blockquote>\n<p>When you type -&gt;, the editor pops up autocomplete choices. Nice. I clicked the run button and the application opened in my web browser. I set a breakpoint on the line; that worked nicely, especially after I displayed the Locals window so I could see the value of variables.<\/p>\n<p>The next step is to implement removing an item. This is fractionally more challenging (I realise this is little more than Hello World), since I need to retrieve the index of the selected item and then work out how to remove it.<\/p>\n<p>I am embarrassed to admit that it took me some time. Yes, I tried the documentation, but it is terrible. Unbelievably bad. Someone ran a thing called <a href=\"http:\/\/www.doc-o-matic.com\">Doc-O-Matic<\/a>&nbsp;over the code. Here&#8217;s the entire description of the ListBox control:<\/p>\n<blockquote>\n<p>A class to encapsulate a listbox control&nbsp;<\/p>\n<\/blockquote>\n<p>There&#8217;s also a reference which lists methods, again with a one-line description if you are lucky.&nbsp;Here&#8217;s the one for ListBox.getItems:<\/p>\n<blockquote>\n<p>This is getItems, a member of class ListBox.<\/p>\n<\/blockquote>\n<p>I gave up on the docs. I had figured out AddItem; I had discovered that the itemindex property has the index of the selected item;&nbsp;but there is no RemoveItem or DeleteItem. I went back to basics. The ListBox has an _items member field which is an array. In PHP you remove an item from an array with unset. I resorted to editing the VCL for PHP by adding a RemoveAt method to CustomListBox:<\/p>\n<blockquote>\n<p>function RemoveAt($index)<br \/>{<br \/>unset($this-&gt;_items[$index]);<br \/>}<\/p>\n<\/blockquote>\n<p>Note that I am not proposing you do the same. There must be a better way to do this. I just couldn&#8217;t work it out quickly from the docs; and I was determined to get this up and running.  <\/p>\n<p>Here&#8217;s my code for removing an item:  <\/p>\n<blockquote>\n<p>$selindex = $this-&gt;lstItems-&gt;itemindex;  <\/p>\n<p>if ( $selindex &gt; -1)<br \/>{<br \/>$this-&gt;lstItems-&gt;RemoveAt($selindex);<br \/>}<\/p>\n<\/blockquote>\n<p>Now my app worked fine. What about deployment? I used the deployment wizard, which essentially copies a bunch of files into a directory, ready for upload. There are a lot. 44 files to be precise, mostly of course the VCL for PHP. Still, it was painless, and you can configure a web server to share these files between different applications. <\/p>\n<p>All I needed to test it was a web server running PHP 5.x (it will not work with PHP 4). Fortunately I had one available, so I uploaded my first Delphi for PHP application. It looked&nbsp;good, but although it worked on my local machine, the deployed app throws an error when you click a button:<\/p>\n<blockquote>\n<p>Application raised an exception class <b>Exception<\/b> with message <b>&#8216;The Input Filter PHP extension is not setup on this PHP installation, so the contents returned by Input is *not* filtered&#8217;<\/b><\/p>\n<\/blockquote>\n<p>I note that <a href=\"http:\/\/neshertech.net\/adler\/?p=58\" target=\"_blank\">this user<\/a> has the same problem. My hunch is that Delphi for PHP requires PHP 5.2 &#8211; I only have 5.1 at the moment.*<\/p>\n<p>In addition,&nbsp;I don&#8217;t like the way the default deployment handles errors, by&nbsp;publishing my callstack to the world, complete with the location of the files on my web server. <\/p>\n<p>How secure are all these VCL for PHP files anyway? What assurance do I have about this? Will they be patched promptly if security issues are discovered?<\/p>\n<p>Important questions.<\/p>\n<p>There will be plenty more to say about Delphi for PHP. For the moment I&#8217;m reserving judgment. I will say that the release looks rushed, which is a shame.<\/p>\n<p><strong>Update<\/strong>: I&#8217;ve now seen a fix posted to the Borland newsgroups for the input filter exception, showing how to remove the code which raises it.&nbsp;However I suggest you do not apply this fix, for security reasons, unless you are deploying on a trusted intranet. It is vital to sanitize PHP input on the internet.<\/p>\n<p>*PHP 5.2 is not the answer. It could even be a problem. Delphi for PHP ships with PHP 5.1. There is an input filter extension which you can add for PHP 5.x; see <a title=\"http:\/\/pecl.php.net\/package\/filter\" href=\"http:\/\/pecl.php.net\/package\/filter\">http:\/\/pecl.php.net\/package\/filter<\/a>. However these are built into PHP 5.2; but the version used by VCL for PHP is old and seems to be&nbsp;incompatible. What a mess.<\/p>\n<p><div class=\"wlWriterSmartContent\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:c12de321-f643-4826-8aba-6e0443d6a362\" contenteditable=\"false\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\">Technorati tags: <a href=\"http:\/\/technorati.com\/tags\/delphi%20for%20php\" rel=\"tag\">delphi for php<\/a>, <a href=\"http:\/\/technorati.com\/tags\/codegear\" rel=\"tag\">codegear<\/a>, <a href=\"http:\/\/technorati.com\/tags\/delphi\" rel=\"tag\">delphi<\/a>, <a href=\"http:\/\/technorati.com\/tags\/php\" rel=\"tag\">php<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I tried out Delphi for PHP for the first time this weekend. Install on Vista was smooth. The setup installs its own copy of Apache 2 and PHP 5. A few minutes later and I was up and running. The IDE is Delphi-like. Here is a scrunched-up image to give you a flavour: &nbsp; I &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/175-delphi-for-php-first-impressions.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Delphi for PHP first impressions<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44,80,96],"tags":[],"class_list":["post-175","post","type-post","status-publish","format-standard","hentry","category-internet","category-software-development","category-web-authoring"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=175"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/175\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}