<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cameron McKay &#187; PHP</title>
	<atom:link href="http://cdmckay.org/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://cdmckay.org/blog</link>
	<description>Programming and Game Development</description>
	<lastBuildDate>Tue, 11 Oct 2011 05:05:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fep Collections</title>
		<link>http://cdmckay.org/blog/2009/07/29/fep-collections/</link>
		<comments>http://cdmckay.org/blog/2009/07/29/fep-collections/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 20:47:57 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Fep]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[dictionaries]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[lists]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=863</guid>
		<description><![CDATA[As I was working on the PHP classes that Fep was to map to, I realized that it was rather silly for me to re-invent an API for lists since there were already many well-designed ones in existence. In particular, I&#8217;ve found that the .NET 3.5 collections API to be particularly nice to use. Moreover, [...]]]></description>
			<content:encoded><![CDATA[<p>As I was working on the PHP classes that Fep was to map to, I realized that it was rather silly for me to re-invent an API for lists since there were already many well-designed ones in existence.  In particular, I&#8217;ve found that the .NET 3.5 collections API to be particularly nice to use.  Moreover, since everyone and their dog and using .NET now, it would also be familiar to most programmers.  Thus, I&#8217;ve decided to use a subset of the .NET collections API for Fep collections.</p>
<p><span id="more-863"></span></p>
<p>Furthermore, after some thought, I&#8217;ve decided to split up Fep arrays.  In PHP arrays aren&#8217;t really arrays in the traditional sense, but more like array/associate array hybrids (JavaScript uses a similar concept).  This can be confusing, error-prone and I don&#8217;t think that the benefits of having an hybrid array system outweighs the complexity.</p>
<p>Thus, in Fep, there will be two main collection types: lists and dictionaries.  Here&#8217;s how a Fep list will look like:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Fep</span>
fep <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;bar&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
fep<span style="color: #339933;">.</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// == 4</span>
fep<span style="color: #339933;">.</span>add<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;baz&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
fep<span style="color: #339933;">.</span>find<span style="color: #009900;">&#40;</span> x <span style="color: #339933;">=&gt;</span> x <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// == 2</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Will compile into this PHP</span>
<span style="color: #000088;">$fep</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FepList<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;baz&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$x</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> x <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And here&#8217;s how a Fep dictionary will look:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Fep</span>
fep <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> blah<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;blah&quot;</span><span style="color: #339933;">,</span> foo<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;zero&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
fep<span style="color: #339933;">.</span>keys<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// == [ &quot;blah&quot;, &quot;foo&quot;, 0 ]</span>
fep<span style="color: #339933;">.</span>containsKey<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;foo&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// == true</span>
fep<span style="color: #339933;">.</span>remove<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;foo&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// == true</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// PHP</span>
<span style="color: #000088;">$fep</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FepDict<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;blah&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;blah&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;foo&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;bar&quot;</span><span style="color: #339933;">,</span> 
         <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;zero&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">keys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">containsKey</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;foo&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fep</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">remove</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;foo&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/07/29/fep-collections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fep Arrays</title>
		<link>http://cdmckay.org/blog/2009/07/24/fep-arrays/</link>
		<comments>http://cdmckay.org/blog/2009/07/24/fep-arrays/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 01:39:55 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Fep]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=827</guid>
		<description><![CDATA[Disclaimer: This is not the way Fep arrays will work. Refer to the new article on Fep collections for more information. In this article, I&#8217;ll write a bit about how I think Fep arrays will look. Keep in mind this a work in progress and is by no means comprehensive. Without further ado&#8230; In PHP, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Disclaimer:</strong> <em>This is not the way Fep arrays will work.  <a href="/blogs/cam/2009/07/29/fep-collections/">Refer to the new article on Fep collections for more information</a>.</em></p>
<p>In this article, I&#8217;ll write a bit about how I think Fep arrays will look.  Keep in mind this a work in progress and is by no means comprehensive.  Without further ado&#8230;</p>
<p>In PHP, you define an array using the <code>array()</code> construct.  Fep will follow the lead of languages like JavaScript, Python, Ruby and Groovy and use the square bracket </code>[]</code> notation.</p>
<h3>Initialization</h3>
<p>For example, a simple array in PHP is creating like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In Fep, this would be done like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span></pre></div></div>

<p><span id="more-827"></span></p>
<p>There are actually three things to notice here.  First, Fep uses square brackets.  Second, Fep has optional semicolons (similar to JavaScript and Scala).  Third, Fep doesn't prefix all variables with <code>$</code>.  This should give your pinky finger a bit of rest and de-noise-ify your Fep code.</p>
<p>How about associative arrays?  In this case, I don't want to deviate too much from PHP, so I'm going to go with the same syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// PHP</span>
<span style="color: #000088;">$fruits</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">&quot;fruits&quot;</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;orange&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;banana&quot;</span><span style="color: #339933;">,</span> 
                     <span style="color: #0000ff;">&quot;c&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;apple&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">&quot;numbers&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">&quot;holes&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;first&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;second&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;third&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Fep</span>
fruits <span style="color: #339933;">=</span> 
<span style="color: #009900;">&#91;</span>
  <span style="color: #0000ff;">&quot;fruits&quot;</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;orange&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;banana&quot;</span><span style="color: #339933;">,</span> 
                <span style="color: #0000ff;">&quot;c&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;apple&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">&quot;numbers&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">&quot;holes&quot;</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;first&quot;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;second&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;third&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#93;</span></pre></div></div>

<h3>Decomposition</h3>
<p>What about that convenient <code>list</code> construct?  In Fep, we'll try again to reduce the typing and improve readability by introducing this syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// PHP</span>
<span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #000088;">$b</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Fep</span>
a<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> c <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#93;</span></pre></div></div>

<h3>Accessors</h3>
<p>To fetch a value from a Fep array, the regular PHP-style accessors will be used, with the main difference being that Fep will support negative indexing.  That is, <code>$array[-1]&nbsp;==&nbsp;$array[$array.length&nbsp;-&nbsp;1]</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span>
println <span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>    <span style="color: #666666; font-style: italic;">// 1</span>
println <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #666666; font-style: italic;">// 5</span>
println <span style="color: #000088;">$arr</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>   <span style="color: #666666; font-style: italic;">// 3</span>
&nbsp;
mixed <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;foo&quot;</span><span style="color: #009900;">&#93;</span>
println arr<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #009900;">&#93;</span> <span style="color: #666666; font-style: italic;">// b</span>
println arr<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span>   <span style="color: #666666; font-style: italic;">// foo</span></pre></div></div>

<h3>API</h3>
<p>All arrays in Fep will be <code>Array</code> objects.  As such, they'll have access to all the PHP array functions in an object-oriented way.  Here's a few examples:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// PHP</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$len</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;z&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$merged</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Fep</span>
arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;x&quot;</span><span style="color: #009900;">&#93;</span>
len <span style="color: #339933;">=</span> arr<span style="color: #339933;">.</span>length
arr<span style="color: #339933;">.</span>push<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;y&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;z&quot;</span><span style="color: #009900;">&#41;</span>
arr<span style="color: #339933;">.</span>contains<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
merged <span style="color: #339933;">=</span> arr <span style="color: #339933;">+</span> <span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;a&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;b&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;c&quot;</span><span style="color: #009900;">&#93;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/07/24/fep-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fep: A cleaner PHP</title>
		<link>http://cdmckay.org/blog/2009/07/24/fep-a-cleaner-php/</link>
		<comments>http://cdmckay.org/blog/2009/07/24/fep-a-cleaner-php/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 22:35:57 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Fep]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=817</guid>
		<description><![CDATA[PHP bugs me. It&#8217;s a language with so many inconsistencies, it&#8217;s just screaming to be cleaned up. I&#8217;m surprised it hasn&#8217;t happened yet. That&#8217;s why I&#8217;m starting a series of articles on Fep, a cleaned up version of PHP. Fep has the following goals: Eliminate many of the inconsistencies of PHP while maintaining the core [...]]]></description>
			<content:encoded><![CDATA[<p>PHP bugs me.  It&#8217;s a language with so many inconsistencies, it&#8217;s just screaming to be cleaned up.  I&#8217;m surprised it hasn&#8217;t happened yet.  That&#8217;s why I&#8217;m starting a series of articles on <strong>Fep</strong>, a cleaned up version of PHP.  </p>
<p><span id="more-817"></span></p>
<p>Fep has the following goals:</p>
<ul>
<li>Eliminate many of the inconsistencies of PHP while maintaining the core <em>feel</em> of the language.  For example, why is there <code>print</code> and <code>echo</code>? Answer: <a href="http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40">it&#8217;s complicated</a>.  But it doesn&#8217;t have to be!  <code>isset()</code> is a language construct that requires brackets but <code>require</code> doesn&#8217;t.  These are the types of things I&#8217;d like to fix.</li>
<li>PHP has a ton of <a href="http://ca2.php.net/manual/en/ref.strings.php">string functions</a> that are just screaming to be separated into classes.  Fep will do this.  This will be also done to groups of functions in a similar state.</li>
<li>PHP isn&#8217;t the nicest language, but it&#8217;s easy and familiar.  It also has a ton of support.  Fep will be a sort of meta-language.  Fep code will be converted to PHP code before it is run in order to maintain compatibility with the PHP ecosystem.</li>
<li>PHP&#8217;s OO model is a bit strange.  Why is the constructor called <code>__construct</code>?  To me that&#8217;s ugly as shit.  I&#8217;m also not a big fan of using <code>-></code> to access methods and attributes.  I&#8217;d much rather use <code>.</code>, but in order to do that, we&#8217;ll probably need to stop using <code>.</code> for concatenation.  I&#8217;m ok with doing that.</li>
</ul>
<p>That&#8217;s just a few of the things of the top of my head.  The development process will follow this pattern:</p>
<ol>
<li>write a series of articles to map out the language (maybe even write a <a href="http://docs.python.org/reference/">language reference like Python</a>),</li>
<li>write a compiler that&#8217;ll convert Fep code into PHP code,</li>
<li>write a module for Apache that&#8217;ll convert <code>.fep</code> files to <code>.php</code> files and then feed them to the PHP module.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/07/24/fep-a-cleaner-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Consuming a J2EE Web Service with PHP SOAP</title>
		<link>http://cdmckay.org/blog/2009/03/05/consuming-a-j2ee-web-service-with-php-soap/</link>
		<comments>http://cdmckay.org/blog/2009/03/05/consuming-a-j2ee-web-service-with-php-soap/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 22:39:59 +0000</pubDate>
		<dc:creator>cdmckay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[j2ee]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[nusoap]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsdl]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/cam/?p=303</guid>
		<description><![CDATA[I recently had to do some work for a company which involved using PHP to consume a J2EE-based WSDL web service. The project was fairly straightforward, involving only a one-way call to the web service, i.e. no result needed to be collected. What is WSDL? Before we start, let&#8217;s talk a bit about what WSDL [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to do some work for a company which involved using <a href="http://www.php.net">PHP</a> to consume a <a href="http://java.sun.com/javaee/">J2EE</a>-based <a href="http://www.w3.org/TR/wsdl">WSDL</a> web service.  The project was fairly straightforward, involving only a one-way call to the web service, i.e. no result needed to be collected.</p>
<p><span id="more-303"></span></p>
<h3>What is WSDL?</h3>
<p>Before we start, let&#8217;s talk a bit about what <a href="http://en.wikipedia.org/wiki/Web_Services_Description_Language">WSDL</a> is.  <em>(Warning: I am very new to WSDL, SOAP and web services in general, so feel free to correct me if I get any of these details wrong).</em></p>
<p>WSDL stands for Web Service Description Language.  As the name suggests, it is an XML language used for describing web services.  By describe, I mean a WSDL file contains information like the functions that a client can call, and data types it uses, and what exceptions it might throw.  This is useful for clients that might contact the web service.  Exactly why that information is useful will become evident in examples below.</p>
<h3>What is SOAP?</h3>
<p>At one point, a long time ago, in a web far far away, <a href="http://en.wikipedia.org/wiki/SOAP_(protocol)">SOAP</a> stood for Simple Object Access Protocol.  Now it stands for nothing.  SOAP is a protocol for exchanging structured information on the web.  Like WSDL, SOAP uses XML.  In fact, SOAP is a protocol often used to exchange WSDL information, although one can also use straight HTTP to do it as well.</p>
<p>All we really need to know (right now) is that a SOAP library permits us to communicate with a WSDL web service that has SOAP bindings (which would be almost any we would encounter in the wild).</p>
<h3>Which library/module to use?</h3>
<p>In order to determine which library to use, I did some googling.  What I found were two options: the <a href="http://sourceforge.net/projects/nusoap/">NuSOAP</a> library and the <a href="http://ca.php.net/manual/en/book.soap.php">PHP SOAP</a> module.</p>
<p>So which one should we use? I initially leaned towards NuSOAP due to the fact that it was an external library, and thus would probably work with almost any PHP installation.  Unfortunately, after perusing the NuSOAP Sourceforge website, I noticed the library hadn&#8217;t been updated since 2005 (a bad sign).  In fact, after further reading, I discovered that, as of PHP 5, the NuSOAP namespace also conflicted with the PHP SOAP module namespace (and hadn&#8217;t yet been fixed).  As a result, I decided to go with the PHP SOAP module.</p>
<h3>The Code</h3>
<p>The first thing anyone needs to do when consuming a WSDL service with PHP is to create a new client object.  By creating a client object, PHP basically reads the server&#8217;s WSDL file and determines which functions are available to us.  A SoapClient is created using the following code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// The path to the WSDL web service.</span>
  <span style="color: #000088;">$wsdl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://path/to/webservice.wsdl&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// The connection options.</span>
  <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'features'</span> <span style="color: #339933;">=&gt;</span> 
    SOAP_USE_XSI_ARRAY_TYPE <span style="color: #339933;">+</span> SOAP_SINGLE_ELEMENT_ARRAYS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Create a new SoapClient.</span>
  <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapClient<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wsdl</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;SoapClient creation successful&lt;br&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>So what&#8217;s going on at line 7?  Those two features are basically used to make the SoapClient act as we&#8217;d expect.  For example, if you don&#8217;t include the SOAP_USE_XSI_ARRAY_TYPE feature, then you&#8217;ll find you get a lot of casting exceptions when dealing with a Java-based webservice that uses any complex data structures.  If you don&#8217;t include the SOAP_USE_XSI_ARRAY_TYPE feature, then PHP will turn 1-element arrays return types into objects, which is not what you want 90% of the time and often gives confusing results.</p>
<p>Now let&#8217;s actually consume a web service.  Let&#8217;s pretend we&#8217;re using the J2EE service provided by this <a href="http://java.sun.com/developer/technicalArticles/J2EE/j2ee_ws/">article</a>.  Here are the contents of the WSDL file from that article:</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="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;definitions</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MyFirstService&quot;</span> <span style="color: #000066;">targetNamespace</span>=<span style="color: #ff0000;">&quot;urn:Foo&quot;</span> <span style="color: #000066;">xmlns:tns</span>=<span style="color: #ff0000;">&quot;urn:Foo&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/wsdl/&quot;</span> <span style="color: #000066;">xmlns:xsd</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:soap</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;types</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MathFace_add&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;int_1&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:int&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;int_2&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:int&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MathFace_addResponse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;part</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;result&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:int&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;portType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MathFace&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;add&quot;</span> <span style="color: #000066;">parameterOrder</span>=<span style="color: #ff0000;">&quot;int_1 int_2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;tns:MathFace_add&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;output</span> <span style="color: #000066;">message</span>=<span style="color: #ff0000;">&quot;tns:MathFace_addResponse&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/operation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/portType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;binding</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MathFaceBinding&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;tns:MathFace&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:binding</span> <span style="color: #000066;">transport</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/http&quot;</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;rpc&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;operation</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;add&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:operation</span> <span style="color: #000066;">soapAction</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:body</span> <span style="color: #000066;">encodingStyle</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;</span> </span>
<span style="color: #009900;">		    <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;encoded&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;urn:Foo&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/input<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;output<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:body</span> <span style="color: #000066;">encodingStyle</span>=<span style="color: #ff0000;">&quot;http://schemas.xmlsoap.org/soap/encoding/&quot;</span> </span>
<span style="color: #009900;">		    <span style="color: #000066;">use</span>=<span style="color: #ff0000;">&quot;encoded&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;urn:Foo&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/output<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/operation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/binding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MyFirstService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;port</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MathFacePort&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;tns:MathFaceBinding&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;soap:address</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;http://localhost:8080/math-service/math&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/port<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/definitions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>What can we tell about the web service by looking at this file?  Well the first thing you should notice is lines 12-14.  In those lines, the web service defines an operation (&#8220;add&#8221;) that takes two arguments (&#8220;int_1 int_2&#8243;).  As a result, we know that the web service exposes an add operation that takes two integer arguments.  Let&#8217;s use that knowledge to invoke the add operation in PHP using the SOAP module:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #666666; font-style: italic;">// The path to the WSDL web service.</span>
  <span style="color: #000088;">$wsdl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://localhost:8080/math-service/math?wsdl&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// The connection options.</span>
  <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'features'</span> <span style="color: #339933;">=&gt;</span> 
    SOAP_USE_XSI_ARRAY_TYPE <span style="color: #339933;">+</span> SOAP_SINGLE_ELEMENT_ARRAYS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Create a new SoapClient.</span>
  <span style="color: #000088;">$client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SoapClient<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wsdl</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;SoapClient creation successful&lt;br&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Call the add operation.</span>
  <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// This should print 4.</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$response</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>How&#8217;d the PHP object $client know to have an add method?  It simply read the WSDL file the same way we did, and realized that the web service exposed that operation.</p>
<p>As you can see, consuming a J2EE web service from a PHP client is not too complicated.  Once you understand the rudiments of a WSDL file and the PHP SOAP module, calling remote functions becomes a snap.</p>
]]></content:encoded>
			<wfw:commentRss>http://cdmckay.org/blog/2009/03/05/consuming-a-j2ee-web-service-with-php-soap/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

