<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Eirik Hoem's Blog &#187; PHP</title>
	<link>http://blog.eirikhoem.net</link>
	<description>Mainly PHP</description>
	<pubDate>Mon, 23 Jun 2008 10:58:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
	<language>en</language>
			<item>
		<title>Simple config management for PHP</title>
		<link>http://blog.eirikhoem.net/index.php/2008/05/30/simple-config-management-for-php/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/05/30/simple-config-management-for-php/#comments</comments>
		<pubDate>Fri, 30 May 2008 07:30:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/05/30/simple-config-management-for-php/</guid>
		<description><![CDATA[When doing complex applications it&#8217;s often nice to have some sort of system for handling settings. PHP has a nice function called parse_ini_file which can be used to create a basic but still usable setting file feature. A simple class which loads the configuration file and offers some methods to retrieve the values for a [...]]]></description>
			<content:encoded><![CDATA[<p>When doing complex applications it&#8217;s often nice to have some sort of system for handling settings. PHP has a nice function called <a href="http://no2.php.net/parse_ini_file" onclick="javascript:pageTracker._trackPageview ('/outbound/no2.php.net');">parse_ini_file</a> which can be used to create a basic but still usable setting file feature. A simple class which loads the configuration file and offers some methods to retrieve the values for a given key is all that&#8217;s needed. The example I&#8217;m providing is pretty basic, but it&#8217;s still very usable and can be added to almost any application.</p>
<p>First, we need to create a file to hold the settings. It&#8217;s ordinary plaintext and follows the INI format.</p>
<p><strong> Here is a quick sample of some key / value pairs:</strong></p>
<p>[general]<br />
locale = no_NO<br />
company.name = MyCompany</p>
<p>datasource.host = localhost<br />
datasource.database = mydb<br />
datasource.username = user<br />
datasource.password = 1234</p>
<p><strong>The class for accessing the file:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">class</span> MyConfigClass<span style="color: #66cc66;">&#123;</span>
  protected <span style="color: #0000ff;">$config</span>;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">config</span> = <span style="color: #000066;">parse_ini_file</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'../conf/myapp.ini'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getConfig<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$key</span> = <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$key</span> !== <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066;">isset</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">config</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$key</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#123;</span>
          <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">config</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$key</span><span style="color: #66cc66;">&#93;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #66cc66;">&#123;</span>
          throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Unknown key '$key' in configuration&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
      <span style="color: #66cc66;">&#125;</span>
      <span style="color: #b1b100;">else</span>
      <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">config</span>;
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setConfig<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$config</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#123;</span>
&nbsp;
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">config</span> = <span style="color: #0000ff;">$config</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Usage:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php"><span style="color: #0000ff;">$configManager</span> = <span style="color: #000000; font-weight: bold;">new</span> MyConfigClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$value</span> = <span style="color: #0000ff;">$configManager</span>-&gt;<span style="color: #006600;">getConfig</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'datasource.host'</span><span style="color: #66cc66;">&#93;</span>;</pre></td></tr></table></div>

<p>Now, when working on larger application one usually have a application like class, and that&#8217;s a nice place to put this code. When using Prado I usually place the config code in the TApplication class.</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/05/30/simple-config-management-for-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Handy online regex tool for PHP, Perl, JS and Python</title>
		<link>http://blog.eirikhoem.net/index.php/2008/04/29/handy-online-regex-tool-for-php-perl-js-and-python/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/04/29/handy-online-regex-tool-for-php-perl-js-and-python/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 10:32:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Perl]]></category>

		<category><![CDATA[Python]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/04/29/handy-online-regex-tool-for-php-perl-js-and-python/</guid>
		<description><![CDATA[



A coworker of mine has been working on a ajax enabled regex tool which lets you evaluate regex expressions in several languages (including PHP PCRE and PHP POSIX) with instant results. You can choose which functions to use, such as match, match all, replace, split etc. It also offers some basic help and hints. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-0056923567680782";
/* default */
google_ad_slot = "6546082201";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
A coworker of mine has been working on a ajax enabled regex tool which lets you evaluate regex expressions in several languages (including PHP PCRE and PHP POSIX) with instant results. You can choose which functions to use, such as match, match all, replace, split etc. It also offers some basic help and hints. It&#8217;s really handy when working on those painful expressions.</p>
<p>You can check it out at <a href="http://regex.larsolavtorvik.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/regex.larsolavtorvik.com');">http://regex.larsolavtorvik.com/</a>. Stop by <a href="http://larsolavtorvik.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/larsolavtorvik.com');">his blog</a> as well.</p>
<p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/Perl" rel="tag">Perl</a>, <a href="http://technorati.com/tag/JavaScript" rel="tag">JavaScript</a>, <a href="http://technorati.com/tag/Python" rel="tag">Python</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/04/29/handy-online-regex-tool-for-php-perl-js-and-python/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Populate PDF templates with PHP / FPDF / FPDI</title>
		<link>http://blog.eirikhoem.net/index.php/2008/04/28/populate-pdf-templates-with-php-fpdf-fpdi/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/04/28/populate-pdf-templates-with-php-fpdf-fpdi/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 13:52:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Frameworks]]></category>

		<category><![CDATA[PDF]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/04/28/populate-pdf-templates-with-php-fpdf-fpdi/</guid>
		<description><![CDATA[



Ever wanted to generated PDF documents on the fly with PHP? Perhaps populate a standard contract with a customers name and address? FPDF and FPDI are two neat libraries which greatly helps when working with PDF files. FPDF is the main library for handling PDF files, while FPDI lets your import existing PDF documents into [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-0056923567680782";
/* default */
google_ad_slot = "6546082201";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />
Ever wanted to generated PDF documents on the fly with PHP? Perhaps populate a standard contract with a customers name and address? FPDF and FPDI are two neat libraries which greatly helps when working with PDF files. FPDF is the main library for handling PDF files, while FPDI lets your import existing PDF documents into the FPDF documents. In the code sample I&#8217;ve prepared here I&#8217;m importing a PDF template document, writing some information to the document, then sending it to the &#8220;customer&#8221;. FPDF offers several neat ways to expose the generated document, such as a stream to the browser, a string, or just storing it to file. You can download <a href="http://blog.eirikhoem.net/wp-content/uploads/2008/04/pdf_sample.zip" title="PDF Sample code">PDF Sample code</a> to test it.</p>
<p>Be sure to head on over to the <a href="http://www.fpdf.org/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.fpdf.org');">FPDF site</a> and <a href="http://www.setasign.de/products/pdf-php-solutions/fpdi/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.setasign.de');">FPDI site</a> for more information on these two libs. <a href="http://blog.eirikhoem.net/wp-content/uploads/2008/04/pdf_sample.zip" title="PDF Sample code"></a></p>
<p><strong>Related posts:</strong><br />
<a href="http://blog.eirikhoem.net/index.php/2007/06/15/generated-pdfs-over-https-with-internet-explorer/">Generated PDFs over HTTPS with Internet Explorer</a></p>
<p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/PDF" rel="tag">PDF</a>, <a href="http://technorati.com/tag/Frameworks" rel="tag">Frameworks</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/04/28/populate-pdf-templates-with-php-fpdf-fpdi/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Google does a Selenium framework?</title>
		<link>http://blog.eirikhoem.net/index.php/2008/04/25/google-does-a-selenium-framework/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/04/25/google-does-a-selenium-framework/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 08:00:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[Testing]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/04/25/google-does-a-selenium-framework/</guid>
		<description><![CDATA[
I just came across this post by Mike Henke, where he writes about a presentation from the Google Automating Testing Conference. Google is working on a framework based on Selenium which they use internally. The post contains some interesting slides in addition to a presentation video.  I&#8217;ve embedded the video in this post for [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--><br />
I just came across this post by <a href="http://henke.ws/machblog/index.cfm?event=showEntry&amp;entryId=6CE7497E-19B9-BA51-EE3B15FA0CAB9A2D" onclick="javascript:pageTracker._trackPageview ('/outbound/henke.ws');">Mike Henke</a>, where he writes about a presentation from the Google Automating Testing Conference. Google is working on a framework based on Selenium which they use internally. The post contains some interesting slides in addition to a presentation video.  I&#8217;ve embedded the video in this post for your convenience, but I suggest you give Mike a visit.</p>
<p><strong>Update: Video removed, please check the links above.</strong></p>
<p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/Testing" rel="tag">Testing</a>, <a href="http://technorati.com/tag/Frameworks" rel="tag">Frameworks</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/04/25/google-does-a-selenium-framework/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Prado Framework 3.1.2 released</title>
		<link>http://blog.eirikhoem.net/index.php/2008/04/24/prado-framework-312-released/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/04/24/prado-framework-312-released/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 09:47:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Frameworks]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Prado]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/04/24/prado-framework-312-released/</guid>
		<description><![CDATA[
My favorite PHP framework just got a new release, adding several new components and fixing 30-ish bugs. The bundled JavaScript libs (Prototype / script.aculo.us) have also been upgraded, so that should help lots of people struggling with the old versions. Head on over to PradoSoft.com to download the new version. If you are new to [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--><br />
My favorite PHP framework just got a new release, adding several new components and fixing 30-ish bugs. The bundled JavaScript libs (Prototype / script.aculo.us) have also been upgraded, so that should help lots of people struggling with the old versions. Head on over to <a href="http://pradosoft.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/pradosoft.com');">PradoSoft.com</a> to download the new version. If you are new to Prado, I recommend checking out the <a href="http://pradosoft.com/demos/quickstart/" onclick="javascript:pageTracker._trackPageview ('/outbound/pradosoft.com');">Prado QuickStart tutorial</a>.</p>
<p><code><p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/Prado" rel="tag">Prado</a>, <a href="http://technorati.com/tag/Frameworks" rel="tag">Frameworks</a></p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/04/24/prado-framework-312-released/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP for science?</title>
		<link>http://blog.eirikhoem.net/index.php/2008/03/20/php-for-science/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/03/20/php-for-science/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 12:53:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/index.php/2008/03/20/php-for-science/</guid>
		<description><![CDATA[
Jonathan Street has posted an article called Is PHP good enough for science? where he asks if anyone has experience with PHP in scientific contexts. I think PHP easily could be used to automate tasks, but I&#8217;m not aware of any toolkits or frameworks created for this purpose. Anyone seen anything like this around? If [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--></p>
<p><a href="http://torrentialwebdev.com/blog/index.php" onclick="javascript:pageTracker._trackPageview ('/outbound/torrentialwebdev.com');">Jonathan Street</a> has posted an article called <a href="http://torrentialwebdev.com/blog/archives/144-Is-PHP-good-enough-for-science.html" onclick="javascript:pageTracker._trackPageview ('/outbound/torrentialwebdev.com');">Is PHP good enough for science?</a> where he asks if anyone has experience with PHP in scientific contexts. I think PHP easily could be used to automate tasks, but I&#8217;m not aware of any toolkits or frameworks created for this purpose. Anyone seen anything like this around? If so, drop him a line.</p>
<p><code><p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a></p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/03/20/php-for-science/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setting xsi:type for objects sent over SOAP (inheritance)</title>
		<link>http://blog.eirikhoem.net/index.php/2008/03/17/setting-xsitype-for-objects-sent-over-soap-inheritance/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/03/17/setting-xsitype-for-objects-sent-over-soap-inheritance/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 14:02:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[SOAP]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[X-Fire]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/?p=28</guid>
		<description><![CDATA[
This post is pretty much a revamp of a previous post called &#8220;Working with X-Fire soap services and inheritance in PHP&#8220;. That title was a bit misleading, and not really that good when it came to providing a sample.
Let&#8217;s say we have a SOAP method called createCustomer(Customer c), and we have a base class called [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--></p>
<p>This post is pretty much a revamp of a previous post called &#8220;<a href="http://blog.eirikhoem.net/index.php/2007/05/21/working-with-x-fire-soap-services-and-inheritance-in-php/">Working with X-Fire soap services and inheritance in PHP</a>&#8220;. That title was a bit misleading, and not really that good when it came to providing a sample.</p>
<p>Let&#8217;s say we have a SOAP method called createCustomer(Customer c), and we have a base class called Customer, which has to subclasses, Person and Organization. Person has firstname, lastname, while Organization as orgname and orgid. Now, the createCustomer call accepts a object of the class Customer, and any derived classes.</p>
<p>When retrieving a Person / Organization over SOAP, PHP automatically creates instances of the correct classes, but when calling createCustomer, passing a Person / Organization it breaks. Out object is sent as a Customer, but with Person or Organization fields added. The SOAP server expects to find a xsi:type for the object we are sending to tell what kind of Customer it is. It seems like PHP does not set this itself (maybe it should?).</p>
<p>I spent quite some time looking for info on how to specify the xsi:type for the objects, and I finally came across <a href="http://no.php.net/manual/en/function.soap-soapvar-construct.php" onclick="javascript:pageTracker._trackPageview ('/outbound/no.php.net');">SoapVar</a>.</p>
<p>I created a base class which the SOAP classes extended. A method called pack is responsible for setting xsi:type.</p>
<p>(I&#8217;m very aware that my pasted code looks like a mess in this blog. I will fix that ASAP).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> BaseClass<span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #0000ff;">$namespace</span> = <span style="color: #ff0000;">&quot;http://model.api.domain.com&quot;</span>; <span style="color: #808080; font-style: italic;">// from your WSDL</span>
  protected <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #000066;">pack</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$obj</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$class_name</span> = <span style="color: #000066;">get_class</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$obj</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0000ff;">$namespace</span> = <span style="color: #ff0000;">&quot;http://model.api.domain.com&quot;</span>;
    <span style="color: #0000ff;">$pack</span> = <span style="color: #000000; font-weight: bold;">new</span> SoapVar<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$obj</span>, XSD_STRING, <span style="color: #ff0000;">&quot;$class_name&quot;</span>, <span style="color: #0000ff;">$namespace</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$pack</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> createCustomer <span style="color: #000000; font-weight: bold;">extends</span> BaseClass<span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setCustomer<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$customer</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$this</span>-&amp;gt;customer = <span style="color: #0000ff;">$this</span>-&amp;gt;pack<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$customer</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">$customer</span> = <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$customer</span>-&amp;gt;setName<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;John Doe&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$request</span> = <span style="color: #000000; font-weight: bold;">new</span> createCustomer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$request</span>-&amp;gt;setAccountID<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">123</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$request</span>-&amp;gt;setCustomer<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$customer</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$client</span>-&amp;gt;createCustomer<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$request</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>That fixed the problems for me atleast.</p>
<p><strong>PS: If your SOAP classes are prefixed you&#8217;ll need to strip the prefix in class_name when creating the SoapVar.</strong></p>
<p><strong> Related posts:</strong></p>
<ul>
<li><a href="http://blog.eirikhoem.net/index.php/2007/05/21/working-with-x-fire-soap-services-and-inheritance-in-php/">Working with X-Fire soap services and inheritance in PHP</a></li>
<li><a href="http://blog.eirikhoem.net/index.php/2008/03/13/array-problems-with-soap-and-php-updated/">Array problems with SOAP and PHP - Updated</a></li>
</ul>
<p><code><p>Technorati Tags: <a href="http://technorati.com/tag/PHP" rel="tag">PHP</a>, <a href="http://technorati.com/tag/SOAP" rel="tag"> SOAP</a></p>                                      </code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/03/17/setting-xsitype-for-objects-sent-over-soap-inheritance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dying with grace - PHP&#8217;s register_shutdown_function</title>
		<link>http://blog.eirikhoem.net/index.php/2008/03/15/dying-with-grace-phps-register_shutdown_function/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/03/15/dying-with-grace-phps-register_shutdown_function/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 11:08:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/?p=27</guid>
		<description><![CDATA[
Update:
I guess I didn&#8217;t make the purpose quite clear here. This method will allow you to show custom error messages when PHP hits a fatal error. The shutdown function will always run.
Scripts tend to die, and that&#8217;s not usually nice. We do not want to show the user a fatal error nor a blank page [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--></p>
<p><strong>Update:</strong></p>
<p>I guess I didn&#8217;t make the purpose quite clear here. This method will allow you to show custom error messages when PHP hits a fatal error. The shutdown function will always run.</p>
<p>Scripts tend to die, and that&#8217;s not usually nice. We do not want to show the user a fatal error nor a blank page (display errors off) . PHP has a function called <a href="http://no2.php.net/register_shutdown_function" onclick="javascript:pageTracker._trackPageview ('/outbound/no2.php.net');">register_shutdown_function</a> which lets us set up a function which is called at execution shutdown. What this means is that our function will be executed when our script is done executing / dying and PHP execution is about to shut down. By setting up a variable to false at the start of our script, and setting it to true at the very end of the script we can have our shutdown function check if the script completed successfully or not. If our variable is still false we know that we never made it to the last line of our script, hence it died somewhere. I&#8217;ve prepared a very basic sample which shows how you can give the user some proper feedback if a fatal error should arise. You&#8217;d want to turn of display of fatal errors for this to look nice.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php"><span style="color: #0000ff;">$clean</span> = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">function</span> shutdown_func<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #000066;">global</span> <span style="color: #0000ff;">$clean</span>;
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$clean</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066;">die</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;not a clean shutdown&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000066;">register_shutdown_function</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'shutdown_func'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$a</span> = <span style="color: #cc66cc;">1</span>;
<span style="color: #0000ff;">$a</span> = <span style="color: #000000; font-weight: bold;">new</span> FooClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// will fail with fatal</span>
&nbsp;
<span style="color: #0000ff;">$clean</span> = <span style="color: #000000; font-weight: bold;">true</span>;
?&amp;gt;</pre></td></tr></table></div>

<p>As you can see, the shutdown_func prints something if the clean variable isn&#8217;t set to true when the shutdown function runs. This should of course be wrapped in a class (and NOT use globals), and for something more usable I recommend checking <a href="http://ezcomponents.org/docs/tutorials/Execution" onclick="javascript:pageTracker._trackPageview ('/outbound/ezcomponents.org');">EZ Components way of doing this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/03/15/dying-with-grace-phps-register_shutdown_function/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Array problems with SOAP and PHP - Updated</title>
		<link>http://blog.eirikhoem.net/index.php/2008/03/13/array-problems-with-soap-and-php-updated/</link>
		<comments>http://blog.eirikhoem.net/index.php/2008/03/13/array-problems-with-soap-and-php-updated/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 08:14:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[SOAP]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/?p=26</guid>
		<description><![CDATA[
This is a follow up to my post about array problems with SOAP and PHP. The scenario was that when an array with only one object was returned over SOAP the array was discarded and pointed straight to the single object.
Cmm was kind enough to tip me this PHP bug report, which explains that this [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--></p>
<p>This is a follow up to <a href="http://blog.eirikhoem.net/index.php/2007/05/23/array-problems-with-x-fire-soap-and-php/">my post about array problems with SOAP and PHP</a>. The scenario was that when an array with only one object was returned over SOAP the array was discarded and pointed straight to the single object.</p>
<p>Cmm was kind enough to tip me <a href="http://bugs.php.net/bug.php?id=36226" onclick="javascript:pageTracker._trackPageview ('/outbound/bugs.php.net');">this PHP bug report</a>, which explains that this is actually not a bug, but a feature.</p>
<p>To get arrays containing one single element, simply create the SoapClient as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php"><span style="color: #0000ff;">$x</span> = <span style="color: #000000; font-weight: bold;">new</span> SoapClient<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$wsdl</span>, <span style="color: #000066;">array</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'features'</span> =&amp;gt; SOAP_SINGLE_ELEMENT_ARRAYS<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p><strong> Related articles:</strong></p>
<ul>
<li><a href="http://blog.eirikhoem.net/index.php/2007/05/23/array-problems-with-x-fire-soap-and-php/">Array problems with X-Fire, SOAP and PHP</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2008/03/13/array-problems-with-soap-and-php-updated/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Why Delphi for PHP should have used Prado instead of VCL</title>
		<link>http://blog.eirikhoem.net/index.php/2007/09/14/why-delphi-for-php-should-have-used-prado-instead-of-vcl/</link>
		<comments>http://blog.eirikhoem.net/index.php/2007/09/14/why-delphi-for-php-should-have-used-prado-instead-of-vcl/#comments</comments>
		<pubDate>Fri, 14 Sep 2007 11:20:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Delphi for PHP]]></category>

		<category><![CDATA[Frameworks]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Prado]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[VCL4PHP]]></category>

		<guid isPermaLink="false">http://blog.eirikhoem.net/?p=25</guid>
		<description><![CDATA[
I recently went to a presentation where some guys from CodeGear showcased Delphi for PHP and VCL4PHP. It&#8217;s a new product which enables PHP developers to use drag / drop and wysiwyg methods to build applications with PHP. The IDE uses VCL4PHP as the underlying framework.
This kind of tool is something that ASP.net has had [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#shortadd--></p>
<p>I recently went to a presentation where some guys from <a href="http://www.codegear.com/" onclick="javascript:pageTracker._trackPageview ('/outbound/www.codegear.com');">CodeGear</a> showcased <a href="http://www.codegear.com/products/delphi/php" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/www.codegear.com');">Delphi for PHP</a> and <a href="http://sourceforge.net/projects/vcl4php" onclick="javascript:pageTracker._trackPageview ('/outbound/sourceforge.net');">VCL4PHP</a>. It&#8217;s a new product which enables PHP developers to use drag / drop and wysiwyg methods to build applications with PHP. The IDE uses VCL4PHP as the underlying framework.</p>
<p>This kind of tool is something that ASP.net has had for a long time (ie Visual Studio.net). Not only does it make the development process easier when it comes to building applications, but it also handles setup of applications, default configs etc. Until now there hasn&#8217;t been any tools for doing this with PHP, so I sincerely congratulate CodeGear on getting something out to the masses. Their IDE is a really nice tool with lots of potential. It ships with apache, and has lots of nice features like a integrated debugger etc. The immediate draw-back is that it runs on Windows only. My impression is that most PHP developers (atleast above hobby level) works on Linux based workstations, so I imagine getting a strong user base could prove to be difficult.</p>
<p>Now, why do I think that Prado is far superior to VCL, and why would it have been a better choice:</p>
<p><strong>1.Exception handling</strong><br />
Any framework which are viable for larger scale application development should use exceptions. It&#8217;s an established way of controlling code flow and making sure the code can recover from error.</p>
<p>VCL:  This is the first MAJOR flaw which would possibly be the hardest to fix. I&#8217;ve spent some time looking around in the VCL code, and there is some basic exception handling here and there. The problem is that most of the controls does not have any exception handling at all. This makes it very hard and tedious to control the follow when errors occur.</p>
<p>Prado: Usage of exceptions throughout the whole framework, with the possibility to have custom exception handlers lays the foundation implementing proper flows in the application and user friendly feedback when errors occur.</p>
<p><strong>2. Usage with other PHP frameworks</strong><br />
A framework needs to play nice with other framework these days. There is no framework that has everything, so the coder will most likely use any given framework in addition to something else.</p>
<p>VCL: None of the controls I&#8217;ve seen while checking out the VCL source code are prefixed. Having controls with class names like ListView, PageControl, TreeNode etc won&#8217;t play nice with other frameworks. Also, using class names like Object and Component isn&#8217;t something you&#8217;d want to have in a framework.</p>
<p>Prado: All components in Prado are prefixed with a &#8216;T&#8217; like TLabel, TPage, TListView ensures cooperation with other frameworks.</p>
<p><strong>3. Generation of HTML code from controls</strong><br />
VCL: The controls implement a method called dumpContents which basically writes HTML and JavaScript tags and attributes by using echo. Some sub classing is done where the parent renders as well.</p>
<p>The following snip is taken from their CustomLabel code:<br />
552                if (trim($this-&gt;LinkTarget)!=&#8221;") $target=&#8221;target=\&#8221;$this-&gt;LinkTarget\&#8221;";<br />
553<br />
554                $class = ($this-&gt;Style != &#8220;&#8221;) ? &#8220;class=\&#8221;$this-&gt;StyleClass\&#8221;" : &#8220;&#8221;;<br />
555<br />
556                echo &#8220;&lt;div id=\&#8221;$this-&gt;_name\&#8221; $style $alignment $hint $class&#8221;;<br />
557<br />
558                if ($this-&gt;_link==&#8221;") echo &#8220;$events&#8221;;<br />
559<br />
560                echo &#8220;&gt;&#8221;;<br />
561<br />
562                if ($this-&gt;_link != &#8220;&#8221;)  echo &#8220;&lt;A href=\&#8221;$this-&gt;_link\&#8221; $target</p>
<p>By letting most of the controls be responsible for writing the low-level HTML code it&#8217;s much harder to keep the code XHTML valid, and does not exactly scream re-use. See next point for how Prado handles this.</p>
<p>Prado: Controls that render contents in Prado extends TWebControl. I&#8217;d like to quote the <a href="http://pradosoft.com/docs/manual/System.Web.UI.WebControls/TWebControl.html" onclick="javascript:pageTracker._trackPageview ('/outbound/pradosoft.com');">Prado manual for TWebControl</a> here:<br />
<em>&#8220;TWebControl is the base class for controls that share a common set of UI-related properties and methods. TWebControl-derived controls are usually associated with HTML tags. They thus have tag name, attributes and body contents. You can override getTagName to specify the tag name, addAttributesToRender to specify the attributes to be rendered, and renderContents to customize the body content rendering. TWebControl encapsulates a set of properties related with CSS style fields, such as BackColor, BorderWidth, etc.</em></p>
<p><em>Subclasses of TWebControl typically needs to override addAttributesToRender and renderContents. The former is used to render the attributes of the HTML tag associated with the control, while the latter is to render the body contents enclosed within the HTML tag.&#8221;</em></p>
<p><strong>4. XHTML code generation</strong><br />
Producing valid XHTML is something we should all strive to do. Not doing so may result in display problems in most browsers.</p>
<p>VCL: I tried to <a href="http://validator.w3.org/check?verbose=1&amp;uri=http%3A%2F%2Fdemos.delphi-php.net%2Fwebsitedemo%2Fhome.php" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/validator.w3.org');">validate a basic demo site</a> created with Delphi for PHP and VCL4PHP. The results speaks for them selves. The generated HTML code is not XHTML compliant. Example from the CustomLabel code again - echo &#8220;&lt;A href=\&#8221;$this-&gt;_link\&#8221; $target. Remember that XHTML tags are always lowecase. There are several other problems as well, and the validation link shows some of them.</p>
<p>Prado: The HTML code that Prado generates is mainly done in the parent controls, so keeping the base implementations XHTML valid mostly ensures that the child controls will be as well. This also removes the actual rendering code from the controls, so creating new controls is far easier and cleaner.</p>
<p><strong>5. Validation controls</strong><br />
Input validation is some of the most boring tasks when writing web applications, and it can be fairly difficult to get it right.</p>
<p>VCL: According to the guy from the presentation there is none, but I found a screen cast <a href="http://www.qadram.com/vcl4php/index.php?ac=16" onclick="javascript:pageTracker._trackPageview ('/outbound/www.qadram.com');">here</a>. It seems way more tedious than the Prado way, and I can&#8217;t tell if it&#8217;s released or just in trunk / testing at the moment.</p>
<p>Prado: Prado ship with several validation controls which works both client side and server side. TRequiredFieldValidator, TRegularExpressionValidator and TEmailAddressValidator ensure that the coder can feel very safe when it comes to validating input. TCustomValidator lets the user create custom validation logic to perform tasks (for example login checks). A complete list and usage examples can be found <a href="http://www.pradosoft.com/demos/quickstart/?page=Controls.Validation" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/www.pradosoft.com');">here</a>.</p>
<p><strong>6. Encapsulation</strong><br />
Encapsulation is a way to make sure that the internal state of classes isn&#8217;t messed with by code that should not be able to.</p>
<p>VCL: I&#8217;ve been looking trough the code trying to find controls that actually use private methods for managing their internals. As far as I can see there is only a fraction of the controls which uses private methods, and when they do it&#8217;s only for one or two methods. This is a design no-no when everyone can call everything.</p>
<p>Prado: Only methods which have to be public are public. This ensures proper encapsulation and prevents the coder from accidentally messing up the state of a control.</p>
<p><strong>7. Component properties</strong></p>
<p>VCL: Delphi for PHP stores all component properties in XML files. I see the point of doing this for the sake of the IDE, but when it comes to runtime code I do not. During the demo they showcased how to use <a href="http://smarty.php.net/" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/smarty.php.net');">smarty</a> templates with VCL, and to add a control which was created in the RAD gui they use markup ala {button1}.</p>
<p>Prado: Prado separates the code and login into two files (.php which holds the page class, and .page which holds the markup). The properties for the components are kept in the .page files which is a much easier way to look at the controls when creating markup.  <a href="http://pradosoft.com/demos/quickstart/?page=GettingStarted.HelloWorld" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/pradosoft.com');">Check this link</a> for a quick intro to how Prado handles this.</p>
<p><strong>8. Usage of globals</strong><br />
VCL: Using globals? We all know this is bad and belongs pretty much belongs in PHP4 applications. If you need a dirty hack it can be a last resort kind of thing, but using it throughout the whole framework?</p>
<p>Example of globals usage:<br />
30 $exceptions_enabled=true;<br />
31<br />
32 global $use_html_entity_decode;<br />
33<br />
34 $use_html_entity_decode=true;<br />
35<br />
36 global $output_enabled;<br />
37<br />
38 $output_enabled=true;<br />
39<br />
40 global $checkduplicatenames;<br />
41<br />
42 $checkduplicatenames=true;</p>
<p>183<br />
184 /**<br />
185  * Global $application variable<br />
186  */<br />
187 $application=new Application(null);<br />
188 $application-&gt;Name=&#8221;vclapp&#8221;;<br />
189</p>
<p>These things should be config related and stored in either the application object or a core base class.</p>
<p>I also checked out the blog demo <a href="http://www.qadram.com/vcl4php/index.php?ac=1900" target="_blank" onclick="javascript:pageTracker._trackPageview ('/outbound/www.qadram.com');">from this page</a>, and usage of globals can be found throughout the applications (global $BlogDB, global $AdminDeleteComment etc).</p>
<p>Prado:<br />
Prado uses globals in one single file, and that&#8217;s the file responsible for generating client side scripts. Settings which span the whole application can usually be accessed from the application object.</p>
<p><strong>9. Ajax</strong></p>
<p>I&#8217;m considering to do another post comparing the ajax features in depth, but I just wanted to point out one thing seen in <a href="http://www.qadram.com/vcl4php/movies/Ajax/ajax_optimizations.htm" onclick="javascript:pageTracker._trackPageview ('/outbound/www.qadram.com');">this screencast</a> on AJAX. The coder escapes from PHP to write the javascript, then jumps back into PHP. In Prado things like these follow the same design as the rest of the framework.</p>
<p><strong>Conclusion</strong></p>
<p>I want to do some more in depth comparisons of controls and ajax support later on, but my current impression of VCL4PHP is that it&#8217;s &#8220;out of date&#8221; or not quite on a professional level. Not taking advantage of PHP5 features like interfaces and encapsulation, lacking proper exception handling, key features like validation and not generating valid XHTML code are all major points which I would expect a proper framework to have in place. One has to wonder why CodeGear went in this direction.</p>
<p>If you consider using VCL / Delphi for PHP I recommend that you first stop by the <a href="http://www.qadram.com/vcl4php/forums/viewforum.php?f=3" onclick="javascript:pageTracker._trackPageview ('/outbound/www.qadram.com');">VCL4PHP</a> forums to get some impressions on how people are using it and see their experiences.</p>
<p>I would really like to come in contact with someone that knows VCL4PHP so that a in depth comparison of the different controls can be done.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eirikhoem.net/index.php/2007/09/14/why-delphi-for-php-should-have-used-prado-instead-of-vcl/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
