<?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>andPHP.com &#187; PHP</title>
	<atom:link href="http://www.andphp.com/category/web-development/php-web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andphp.com</link>
	<description>Web Development Tips, Tricks &#38; Much More</description>
	<lastBuildDate>Tue, 06 Apr 2010 19:41:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>iBuldings.com PHP 5.3 Migrating Guide</title>
		<link>http://www.andphp.com/2009/06/30/ibuldings-com-php-5-3-migrating-guide/</link>
		<comments>http://www.andphp.com/2009/06/30/ibuldings-com-php-5-3-migrating-guide/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 20:28:59 +0000</pubDate>
		<dc:creator>Luiz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[migrating]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php 5.3]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.andphp.com/?p=26</guid>
		<description><![CDATA[Cal Evans has been kind enough to provide the PHP World with a guide to migrating to PHP 5.3, which can be found in the TechPortal.
Make sure to read the Release Announcement as you familiarize yourself with the new features, and improvements. 

As PHP developers download and start testing the biggest change to the language [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/calevans">Cal Evans</a> has been kind enough to provide the PHP World with a guide to migrating to PHP 5.3, which can be found in the <a href="http://techportal.ibuildings.com/" title="PHP For Professional Developers">TechPortal</a>.</p>
<p>Make sure to read the <a href="http://php.net/releases/5_3_0.php">Release Announcement</a> as you familiarize yourself with the new features, and improvements. </p>
<blockquote><p>
As PHP developers download and start testing the biggest change to the language in 7 years, many are wondering not about Santa’s bag full of new toys for them to use in building tomorrow’s applications but about the changes in the language that will affect yesterday’s applications.<br />
&#8230;<br />
The following is a distillation of the PHP 5.3 migration guide. We only cover those items most likely to affect legacy 5.x code.</p></blockquote>
<p>The full guide can be found in the <a href="http://techportal.ibuildings.com/2009/06/30/migrating-to-php-5-3/">iBuildings Blog</a> </p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.andphp.com/2009/06/30/php-5-3-released/" title="PHP 5.3 Released">PHP 5.3 Released</a></li><li><a href="http://www.andphp.com/2008/03/04/php-namespaces-is-not-years-away-to-be-included-in-php-53/" title="PHP Namespaces Is Not Years Away, Now In PHP 5.3">PHP Namespaces Is Not Years Away, Now In PHP 5.3</a></li><li><a href="http://www.andphp.com/2008/03/04/resize-images-with-this-php-script/" title="Resize images with this PHP script">Resize images with this PHP script</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.andphp.com/2009/06/30/ibuldings-com-php-5-3-migrating-guide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP 5.3 Released</title>
		<link>http://www.andphp.com/2009/06/30/php-5-3-released/</link>
		<comments>http://www.andphp.com/2009/06/30/php-5-3-released/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 20:15:00 +0000</pubDate>
		<dc:creator>Luiz</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php 5.3]]></category>

		<guid isPermaLink="false">http://www.andphp.com/?p=23</guid>
		<description><![CDATA[It is finally here.  PHP 5.3 has been released and like we mentioned before (PHP Namespaces Is Not Years Away, Now In PHP 5.3).  It supports Namespaces. 
Related PostsiBuldings.com PHP 5.3 Migrating GuidePHP Namespaces Is Not Years Away, Now In PHP 5.3Resize images with this PHP script]]></description>
			<content:encoded><![CDATA[<p>It is finally here.  <a href="http://php.net/releases/5_3_0.php">PHP 5.3</a> has been released and like we mentioned before (<a href="http://www.andphp.com/2008/03/04/php-namespaces-is-not-years-away-to-be-included-in-php-53/">PHP Namespaces Is Not Years Away, Now In PHP 5.3</a>).  It supports <a href="http://us.php.net/namespaces">Namespaces</a>. </p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.andphp.com/2009/06/30/ibuldings-com-php-5-3-migrating-guide/" title="iBuldings.com PHP 5.3 Migrating Guide">iBuldings.com PHP 5.3 Migrating Guide</a></li><li><a href="http://www.andphp.com/2008/03/04/php-namespaces-is-not-years-away-to-be-included-in-php-53/" title="PHP Namespaces Is Not Years Away, Now In PHP 5.3">PHP Namespaces Is Not Years Away, Now In PHP 5.3</a></li><li><a href="http://www.andphp.com/2008/03/04/resize-images-with-this-php-script/" title="Resize images with this PHP script">Resize images with this PHP script</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.andphp.com/2009/06/30/php-5-3-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Namespaces Is Not Years Away, Now In PHP 5.3</title>
		<link>http://www.andphp.com/2008/03/04/php-namespaces-is-not-years-away-to-be-included-in-php-53/</link>
		<comments>http://www.andphp.com/2008/03/04/php-namespaces-is-not-years-away-to-be-included-in-php-53/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 17:07:00 +0000</pubDate>
		<dc:creator>Jamal</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[php 5.3]]></category>
		<category><![CDATA[php 6]]></category>
		<category><![CDATA[php namespaces]]></category>

		<guid isPermaLink="false">http://www.andphp.com/2008/03/04/php-namespaces-is-not-years-away-to-be-included-in-php-53/</guid>
		<description><![CDATA[This article is outdated, for more information on PHP Namespaces please check the PHP Manual.
Namespaces have been around for quite a while in Object Oriented programming with languages such Java. Basically, for those of you who have not used them, it means that you can create a context or package for a set of variables, [...]]]></description>
			<content:encoded><![CDATA[<p><span style="background-color: #FFFDE5;" ><strong style="color: #930">This article is outdated, for more information on PHP Namespaces please check the <a href="http://us.php.net/manual/en/language.namespaces.php" rel="nofollow" title="PHP: Namespaces - Manual">PHP Manual</a>.</strong></span></p>
<p>Namespaces have been around for quite a while in Object Oriented programming with languages such Java. Basically, for those of you who have not used them, it means that you can create a context or package for a set of variables, functions and classes to prevent same named objects from different packages to conflict.</p>
<pre class="brush: php;">&lt;?php

/* PHP Namespace sample */
namespace Project::Sample;

class Foo {
  function bar () {
    echo "Test namespace function";
  }
}

// since Project::Sample is the current namespace
$foo = new Foo();

// or using the full namespace
$foo = new Project::Sample::Foo();

// or using the use keyword
use Project::Sample as Sample

$foo = new Sample::Foo();

$foo-&gt;bar(); // Prints: Test namespace function
?&gt;</pre>
<p><span id="more-15"></span></p>
<p>Currently, the only solution is to prefix objects within a package or project with the project name. This method works, but it creates large names and repetition.</p>
<p>For example, say you have a blog project that you named MyBlog and a company named MyCompany, the following code could be a sample of the article class.</p>
<pre class="brush: php;">
&lt;?php

class MyCompany_MyBlog_Article {
  private $title;

  public function setTitle($title) {
    $this-&gt;title = $title;
  }

  public function getTitle() {
    return $this-&gt;title;
  }
}
?&gt;</pre>
<p>This currently works, yes. The problem is that any time you want to call the Article class created above you have to use MyBlog_Article. Namespaces solve this problem.</p>
<h3>Creating namespaces</h3>
<p>Here is what the above code would look like using namespaces instead.</p>
<pre class="brush: php;">
&lt;?php

namespace MyCompany::MyBlog;

class Article {
  private $title;

  public function setTitle($title) {
    $this-&gt;title = $title;
  }

  public function getTitle() {
    return $this-&gt;title;
  }
}
?&gt;</pre>
<p>At a first glance, there is little difference in the code. In fact, the second sample has more code because of the <em>namespace</em> keyword. Namespaces do provide improvement though. First, any object that is created after the namespace call will be placed under that namespace. So you can create multiple objects without including MyBlog for each one. Additionally, if you were to decide to change the name of the project or package, all you have to do is change the namespace call. All the other objects would fall under the new naming. Lastly, calling the objects becomes a lot simpler, as you will not have to directly reference the full name of the object including the namespace every time you need it.</p>
<h3>Using namespaces</h3>
<p>Lets look at how we could use the above article class with namespaces.</p>
<pre class="brush: php;">
&lt;?php

require ("/path/to/class/mycompany.myblog.article.php");
use MyCompany::MyBlog;

$article = new MyBlog::Article();
$article-&gt;setTitle('Sample Title');
echo $article-&gt;getTitle(); // Prints: Sample Title
?&gt;</pre>
<p>Now this is where the beauty of namespaces comes in to play. The <em>use</em> keyword sets the namespace locally so you do not have to call objects within it with the full namespace, so instead of using MyCompany::MyBlog::Article you can simply use MyBlog::Article as is shown in the example above. You can always use the article object without the use keyword.</p>
<pre class="brush: php;">
&lt;?php

require ("/path/to/class/mycompany.myblog.article.php");

$article = new MyCompany::MyBlog::Article();
?&gt;</pre>
<h3>Multiple Namespaces and Aliases</h3>
<p>A great feature of namespaces is being able to use multiple namespaces at once. Say you are writing a plugin to write to multiple blogs at once (I have no clue why you would need one), with namespaces you would not have conflicting object names to deal with. Lets take a look at using the objects MyCompany::MyBlog::Article and OtherBlog::Article.</p>
<pre class="brush: php;">
&lt;?php

require ("/path/to/class/mycompany.myblog.article.php");
require ("/path/to/class/otherblog.article.php");

use MyCompany::MyBlog as My;
use OtherBlog as Other;

$myarticle = new My::Article();
$otherarticle = new Other::Article();
// ...
?&gt;</pre>
<p>Using <em>as</em> after the <em>use</em> keyword will create an alias of the namespace to make it easier to use.</p>
<h3>Namespace Constants</h3>
<p>You can define namespace constats using the the const keyword within a namespace.</p>
<pre class="brush: php;">
&lt;?php

namespace MyCompany::MyBlog;

const VERSION = '0.1.1';

echo MyCompany::MyBlog::VERSION; // Prints: 0.1.1
?&gt;</pre>
<p>You can also call constants using namespace aliases created with the use keyword. You can also call class constants the same way.</p>
<pre class="brush: php;">
&lt;?php

namespace MyCompany::MyBlog;

class Article {
  const VERSION = '0.1.1';
}

echo MyCompany::MyBlog::Article::VERSION; // Prints: 0.1.1
?&gt;</pre>
<h3>Autoloading namespaces</h3>
<p>Another great feature of namespaces is the autoload support. When calling a class by its namespace, the full class name, including namespaces, will be passed to the __autoload function, even when using a namespace alias.</p>
<pre class="brush: php;">
&lt;?php

function __autoload($name) {
  $name = strtolower($name);
  $name = str_replace('::', '.', $name);
  require_once $name . '.php';
}

use MyCompany::MyBlog as Blog;

$article = new Blog::Article();
?&gt;</pre>
<p>One issue that does arise with namespaces is being able to call a global function from within a namespace. To call a global function you would need to prefix an empty scope operator (::).</p>
<pre class="brush: php;">
&lt;?php

namespace package;

function test() {
  echo "Calling the packaged test function";
}

test(); // Prints: Calling the packaged test function

::test(); // Prints: Calling the global test function
?&gt;</pre>
<pre class="brush: php;">
&lt;?php

function test() {
  echo "Calling the global test function";
}

require('package.php');
?&gt;</pre>
<p>If you want to play around with this yourself you can grab a snapshot of PHP 5.3 from <a href="http://snaps.php.net">http://snaps.php.net/</a> (You can even get PHP 6 from there).</p>
<p>Now, all we have to do is wait until PHP 5.3 is stable and released. Since 5.3 is just a minor revision number most hosting providers would be more willing to update than if it was PHP 6. Therefore, namespaces support will take less time to be globally supported. This is very exciting news.</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li><a href="http://www.andphp.com/2009/06/30/ibuldings-com-php-5-3-migrating-guide/" title="iBuldings.com PHP 5.3 Migrating Guide">iBuldings.com PHP 5.3 Migrating Guide</a></li><li><a href="http://www.andphp.com/2009/06/30/php-5-3-released/" title="PHP 5.3 Released">PHP 5.3 Released</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.andphp.com/2008/03/04/php-namespaces-is-not-years-away-to-be-included-in-php-53/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
