<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to call functions from another class.</title>
	<atom:link href="http://www.killerphp.com/articles/how-to-call-functions-from-another-class/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.killerphp.com/articles/how-to-call-functions-from-another-class/</link>
	<description>Dedicated to teaching web designers PHP.</description>
	<lastBuildDate>Mon, 29 Aug 2011 11:56:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Stefan Mischook</title>
		<link>http://www.killerphp.com/articles/how-to-call-functions-from-another-class/comment-page-1/#comment-94335</link>
		<dc:creator>Stefan Mischook</dc:creator>
		<pubDate>Fri, 17 Jul 2009 01:32:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.killerphp.com/articles/?p=149#comment-94335</guid>
		<description>Hi,

Can you repost your question on the PHP forum:

http://www.killersites.com/forums/forum/12/php/

Thanks,

Stefan</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Can you repost your question on the PHP forum:</p>
<p><a href="http://www.killersites.com/forums/forum/12/php/" rel="nofollow">http://www.killersites.com/forums/forum/12/php/</a></p>
<p>Thanks,</p>
<p>Stefan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob</title>
		<link>http://www.killerphp.com/articles/how-to-call-functions-from-another-class/comment-page-1/#comment-94301</link>
		<dc:creator>Rob</dc:creator>
		<pubDate>Thu, 16 Jul 2009 12:39:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.killerphp.com/articles/?p=149#comment-94301</guid>
		<description>I have a possibly similar question about already instantiated classes. Based on what I have seen on other sites I have something like this:

---class.login.php
class login
{ 
var $loginID; var $role; ....
function getCurrentLogin() {$this-&gt;loginID=.... }

function displayUserOptions() {echo &quot;Welcome &quot;.this-&gt;name ...}
}

---class.navigation.php
class navigation
{
var currentPage; var menuStructure; ....

function displayNavigation($currentLogin)
{
    code to display menus;
    $currentLogin-&gt;displayUserOptions();
}

----index.php
include(class.login.php);
include(class.navigation.php);
if(!isset($_SESSION[&quot;$currentLogin&quot;])){
$_SESSION[&quot;$currentLogin&quot;] = new login;}
$_SESSION[&quot;$currentLogin&quot;]-&gt;checkOrGetCurrentLogin();

if(!isset($_SESSION[&quot;$navigation&quot;])){
$_SESSION[&quot;$navigation&quot;] = new navigation;}
$_SESSION[&quot;$navigation&quot;]-&gt;displayNavigation($_SESSION[&quot;$currentLogin&quot;])

The navigation bar displays fine then I get Call to undefined method login::displayUserOptions()</description>
		<content:encoded><![CDATA[<p>I have a possibly similar question about already instantiated classes. Based on what I have seen on other sites I have something like this:</p>
<p>&#8212;class.login.php<br />
class login<br />
{<br />
var $loginID; var $role; &#8230;.<br />
function getCurrentLogin() {$this-&gt;loginID=&#8230;. }</p>
<p>function displayUserOptions() {echo &#8220;Welcome &#8220;.this-&gt;name &#8230;}<br />
}</p>
<p>&#8212;class.navigation.php<br />
class navigation<br />
{<br />
var currentPage; var menuStructure; &#8230;.</p>
<p>function displayNavigation($currentLogin)<br />
{<br />
    code to display menus;<br />
    $currentLogin-&gt;displayUserOptions();<br />
}</p>
<p>&#8212;-index.php<br />
include(class.login.php);<br />
include(class.navigation.php);<br />
if(!isset($_SESSION["$currentLogin"])){<br />
$_SESSION["$currentLogin"] = new login;}<br />
$_SESSION["$currentLogin"]-&gt;checkOrGetCurrentLogin();</p>
<p>if(!isset($_SESSION["$navigation"])){<br />
$_SESSION["$navigation"] = new navigation;}<br />
$_SESSION["$navigation"]-&gt;displayNavigation($_SESSION["$currentLogin"])</p>
<p>The navigation bar displays fine then I get Call to undefined method login::displayUserOptions()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan Mischook</title>
		<link>http://www.killerphp.com/articles/how-to-call-functions-from-another-class/comment-page-1/#comment-83077</link>
		<dc:creator>Stefan Mischook</dc:creator>
		<pubDate>Thu, 22 Jan 2009 23:14:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.killerphp.com/articles/?p=149#comment-83077</guid>
		<description>Glad I could help!!

;)

Stefan</description>
		<content:encoded><![CDATA[<p>Glad I could help!!</p>
<p> <img src='http://www.killerphp.com/articles/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Stefan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.killerphp.com/articles/how-to-call-functions-from-another-class/comment-page-1/#comment-83076</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Thu, 22 Jan 2009 22:53:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.killerphp.com/articles/?p=149#comment-83076</guid>
		<description>You know what? I don&#039;t need to use $this when referencing variables passed into the methods in classes. I think by removing &quot;this-&gt;&quot;, the code example will work. I answered my own question :D

Thanks again!</description>
		<content:encoded><![CDATA[<p>You know what? I don&#8217;t need to use $this when referencing variables passed into the methods in classes. I think by removing &#8220;this-&gt;&#8221;, the code example will work. I answered my own question <img src='http://www.killerphp.com/articles/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Thanks again!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.killerphp.com/articles/how-to-call-functions-from-another-class/comment-page-1/#comment-83075</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Thu, 22 Jan 2009 22:47:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.killerphp.com/articles/?p=149#comment-83075</guid>
		<description>Thank you for this tutorial. My question is, how do you call a function from another class if the classes are both instantiated from outside the classes (out at index.php, for example)?

For example, I have my class &quot;website&quot;, which executes session_start() among other things. My website class also houses encryption methods.

In my &quot;pages&quot; class, which I instantiate to create a page, it needs access to these encryption methods.

So these are instantiated from index.php, and I can&#039;t instantiate website class twice, since it runs code that should only be executed once per page load.

I could pass my &quot;website&quot; object path when instantiating &quot;pages&quot;, but the code:

class page
{
	public $website
	function __construct($website)
	{
		$this-&gt;website-&gt;encrypt();
	}
}

Fails to work. How would one get around this?</description>
		<content:encoded><![CDATA[<p>Thank you for this tutorial. My question is, how do you call a function from another class if the classes are both instantiated from outside the classes (out at index.php, for example)?</p>
<p>For example, I have my class &#8220;website&#8221;, which executes session_start() among other things. My website class also houses encryption methods.</p>
<p>In my &#8220;pages&#8221; class, which I instantiate to create a page, it needs access to these encryption methods.</p>
<p>So these are instantiated from index.php, and I can&#8217;t instantiate website class twice, since it runs code that should only be executed once per page load.</p>
<p>I could pass my &#8220;website&#8221; object path when instantiating &#8220;pages&#8221;, but the code:</p>
<p>class page<br />
{<br />
	public $website<br />
	function __construct($website)<br />
	{<br />
		$this-&gt;website-&gt;encrypt();<br />
	}<br />
}</p>
<p>Fails to work. How would one get around this?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

