<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Some More PHP Abilities You May Not Know About</title>
	<atom:link href="http://www.davidjeffries.com/some-more-php-abilities-you-may-not-know-about/feed" rel="self" type="application/rss+xml" />
	<link>http://www.davidjeffries.com/some-more-php-abilities-you-may-not-know-about</link>
	<description>Internet, Programming, And Everything Else That Matters</description>
	<pubDate>Thu, 20 Nov 2008 23:42:32 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Jim Carreer</title>
		<link>http://www.davidjeffries.com/some-more-php-abilities-you-may-not-know-about#comment-306</link>
		<dc:creator>Jim Carreer</dc:creator>
		<pubDate>Wed, 21 May 2008 02:40:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidjeffries.com/?p=89#comment-306</guid>
		<description>Bah, I wrote this comment when I was very tired so the code is riddled with mistakes but if you know anything about PHP you should spot them easy, for some reason it cut off the class def, it was class "Fo" which I'm sure most people understood. The important part is that __set and __get function defs are shown.</description>
		<content:encoded><![CDATA[<p>Bah, I wrote this comment when I was very tired so the code is riddled with mistakes but if you know anything about PHP you should spot them easy, for some reason it cut off the class def, it was class &#8220;Fo&#8221; which I&#8217;m sure most people understood. The important part is that __set and __get function defs are shown.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: E.J. Sexton</title>
		<link>http://www.davidjeffries.com/some-more-php-abilities-you-may-not-know-about#comment-303</link>
		<dc:creator>E.J. Sexton</dc:creator>
		<pubDate>Tue, 20 May 2008 12:57:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidjeffries.com/?p=89#comment-303</guid>
		<description>The ampersand pointer reference is useful, but doesn't always work in PHP. This shows up especially when passing variables by reference to functions and when using pointers in foreach() loops--sometimes it works and sometimes it doesn't. It almost never works when it comes to passing variables by reference repeatedly to recursive functions.

On the whole, I try to avoid using it. If I want to be 100% sure that I'm changing the value of a variable, I modify the original, not the reference. PHP &lt;em&gt;IS&lt;/em&gt; crazy...</description>
		<content:encoded><![CDATA[<p>The ampersand pointer reference is useful, but doesn&#8217;t always work in PHP. This shows up especially when passing variables by reference to functions and when using pointers in foreach() loops&#8211;sometimes it works and sometimes it doesn&#8217;t. It almost never works when it comes to passing variables by reference repeatedly to recursive functions.</p>
<p>On the whole, I try to avoid using it. If I want to be 100% sure that I&#8217;m changing the value of a variable, I modify the original, not the reference. PHP <em>IS</em> crazy&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Jeffries</title>
		<link>http://www.davidjeffries.com/some-more-php-abilities-you-may-not-know-about#comment-301</link>
		<dc:creator>David Jeffries</dc:creator>
		<pubDate>Tue, 20 May 2008 06:03:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidjeffries.com/?p=89#comment-301</guid>
		<description>set &#038; get magic functions are going to be included in my 3rd php tricks post :).  Interesting usage you had there - some of these lesser-known php tricks can create some pretty interesting code.</description>
		<content:encoded><![CDATA[<p>set &#038; get magic functions are going to be included in my 3rd php tricks post :).  Interesting usage you had there - some of these lesser-known php tricks can create some pretty interesting code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Carreer</title>
		<link>http://www.davidjeffries.com/some-more-php-abilities-you-may-not-know-about#comment-300</link>
		<dc:creator>Jim Carreer</dc:creator>
		<pubDate>Tue, 20 May 2008 05:57:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.davidjeffries.com/?p=89#comment-300</guid>
		<description>If you really want to get crazy you can overload the __set and __get magic functions for a class you define.  This can lead to interesting things such as "read-only" variables,  for example

&lt;pre lang="php"&gt;
readOnlyVariable = $param;
    }
    public function __set($name, $value){
          if($name == "readOnlyVariable"){
               trigger_error("Fo::readOnlyVariable cannot be set in this manner");
               return;
           }
           $this-&#62;$name = $value;
    }
    public function __get($name){
           return $this-&#62;$name;
    }
}
var $fo = new Fo($param);
//This is valid
echo Fo-&#62;readOnlyVariable;
//This triggers error 
Fo-&#62;readOnlyVariable = "SomeValue"; 
?&#62;
&lt;/pre&gt;

I've also used this method to set and get values from arrays stored in the class I wrote so that it "appeared" (to the coder using the class) that the array's elements were regular public members of the class that contained said array.  That may sound a bit nonsensical but it was very helpful when I needed to both describe a database table in detail (type, length, etc of the table's columns) with a php array and also have storage for values to insert into said table.</description>
		<content:encoded><![CDATA[<p>If you really want to get crazy you can overload the __set and __get magic functions for a class you define.  This can lead to interesting things such as &#8220;read-only&#8221; variables,  for example</p>
<pre lang="php">
readOnlyVariable = $param;
    }
    public function __set($name, $value){
          if($name == "readOnlyVariable"){
               trigger_error("Fo::readOnlyVariable cannot be set in this manner");
               return;
           }
           $this-&gt;$name = $value;
    }
    public function __get($name){
           return $this-&gt;$name;
    }
}
var $fo = new Fo($param);
//This is valid
echo Fo-&gt;readOnlyVariable;
//This triggers error
Fo-&gt;readOnlyVariable = "SomeValue";
?&gt;
</pre>
<p>I&#8217;ve also used this method to set and get values from arrays stored in the class I wrote so that it &#8220;appeared&#8221; (to the coder using the class) that the array&#8217;s elements were regular public members of the class that contained said array.  That may sound a bit nonsensical but it was very helpful when I needed to both describe a database table in detail (type, length, etc of the table&#8217;s columns) with a php array and also have storage for values to insert into said table.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
