<?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>Query7 &#187; object-oriented basics</title>
	<atom:link href="http://query7.com/tag/object-oriented-basics/feed" rel="self" type="application/rss+xml" />
	<link>http://query7.com</link>
	<description>PHP, Javascript, Python and Web Development</description>
	<lastBuildDate>Sat, 25 Jun 2011 21:29:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Using the keyword &quot;this&quot; in PHP</title>
		<link>http://query7.com/using-this-in-php</link>
		<comments>http://query7.com/using-this-in-php#comments</comments>
		<pubDate>Thu, 08 Jan 2009 16:09:39 +0000</pubDate>
		<dc:creator>Prakash Mohanty</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[object-oriented basics]]></category>

		<guid isPermaLink="false">http://www.webdevelopmentbits.com/?p=345</guid>
		<description><![CDATA[You may come across number of functions, variables inside a class, you
call each one them as object of the class.

The keyword “this” is used in a class in php , to call and use these objects as
shown in the example below.]]></description>
			<content:encoded><![CDATA[<p>You may have come across number of functions and variables inside a class and perhaps you don&#8217;t even know how they&#8217;re called or invoked. These functions and variables that belong to a class are called as properties and methods, or simply members, of this class.</p>
<p>In PHP, the keyword &#8220;<code>$this</code>&#8221; is used as a self reference of a class and you can use it for calling and using these properties and methods as shown in the example bellow.</p>
<p>Create a file ClassOne.php with code bellow:<br />
<code>&lt;?php</code></p>
<pre>
class ClassOne
{
    // this is a property of this class
    public $propertyOne;

    // When the ClassOne is instantiated, the first method called is
    // its constructor, which also is a method of the class
    public function __construct($argumentOne)
    {
        // this key word used here to assign
        // the argument to the class
        $this->propertyOne = $argumentOne;
    }

    // this is a method of the class
    function methodOne()
    {
        //this keyword also used here to use  the value of variable $var1
        return 'Method one print value for its '
             . ' property $propertyOne: ' . $this->propertyOne;
    }
}
</pre>
<p>In this class, we are also using the visibility declarations (public), which means whether the members are accessible on a subclass &#8211; we will discuss it later &#8211; or instance.<br />
Another thing you must be curious about is the use of &#8216;->&#8217;. This is an object pointer and, on PHP, it&#8217;s used for accessing members inside an object.</p>
<p>Now, let&#8217;s test your class! Create another file, called use.php with the following code:<br />
<code>&lt;?php</code></p>
<pre>
// include your class file
require_once 'ClassOne.php';

// Create an instance of your class
$classOneInstance = new ClassOne('Hello');

// And test it
print $classOneInstance->propertyOne . '&lt;br /&gt;';
print $classOneInstance->methodOne();
</pre>
<p>- Note that in both files we&#8217;re not using the enclosing PHP tags (?&gt;). Once they have only PHP code, it&#8217;s not needed and it&#8217;s also a good practice to avoid them on pure PHP files.</p>
]]></content:encoded>
			<wfw:commentRss>http://query7.com/using-this-in-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

