<?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>Education &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/education/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>You think you know &#8230; algorithms?</title>
		<link>/2012/04/11/you-think-you-know-algorithms/</link>
		<comments>/2012/04/11/you-think-you-know-algorithms/#respond</comments>
		<pubDate>Wed, 11 Apr 2012 08:04:34 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[quiz]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Super Quiz]]></category>
		<category><![CDATA[weekly quiz]]></category>

		<guid isPermaLink="false">/?p=3021</guid>
		<description><![CDATA[Note!– By reading this blog you can get the right answers! Loading&#8230; The answers will be published a week after the quiz has started!<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/02/29/you-think-you-know-javascript/" rel="bookmark" title="You think you know &#8230; javascript?">You think you know &#8230; javascript? </a></li>
<li><a href="/2012/03/09/you-think-you-know-php/" rel="bookmark" title="You think you know &#8230; PHP?">You think you know &#8230; PHP? </a></li>
<li><a href="/2012/03/07/you-think-you-know-javascript-quiz-results/" rel="bookmark" title="You think you know javascript. Quiz results!">You think you know javascript. Quiz results! </a></li>
<li><a href="/2012/05/09/you-think-you-know-algorithms-quiz-results-2/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Note!– By reading this blog you can get the right answers!</p>
<p><iframe src="https://docs.google.com/spreadsheet/embeddedform?formkey=dHh3NkJiOTJYYkVNem9RVTNVWVh0V0E6MQ" width="640" height="1000" frameborder="0" marginheight="0" marginwidth="0">Loading&#8230;</iframe></p>
<p>The answers will be published a week after the quiz has started!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/02/29/you-think-you-know-javascript/" rel="bookmark" title="You think you know &#8230; javascript?">You think you know &#8230; javascript? </a></li>
<li><a href="/2012/03/09/you-think-you-know-php/" rel="bookmark" title="You think you know &#8230; PHP?">You think you know &#8230; PHP? </a></li>
<li><a href="/2012/03/07/you-think-you-know-javascript-quiz-results/" rel="bookmark" title="You think you know javascript. Quiz results!">You think you know javascript. Quiz results! </a></li>
<li><a href="/2012/05/09/you-think-you-know-algorithms-quiz-results-2/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/04/11/you-think-you-know-algorithms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some Notes on the Object-oriented Model of PHP</title>
		<link>/2011/10/20/some-notes-on-the-object-oriented-model-of-php/</link>
		<comments>/2011/10/20/some-notes-on-the-object-oriented-model-of-php/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 15:08:15 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[abstract classes]]></category>
		<category><![CDATA[Abstract type]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[experiment]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[iheritance]]></category>
		<category><![CDATA[Interfaces]]></category>
		<category><![CDATA[Java programming language]]></category>
		<category><![CDATA[Method]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Object-oriented programming]]></category>
		<category><![CDATA[php 5]]></category>
		<category><![CDATA[php class definition]]></category>
		<category><![CDATA[php experiment]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[Polymorphism in object-oriented programming]]></category>
		<category><![CDATA[Software design patterns]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Virtual function]]></category>

		<guid isPermaLink="false">/?p=2401</guid>
		<description><![CDATA[PHP 5 introduces interfaces and abstract classes. To become a little clearer, let us see their definitions. Interfaces Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled. Interfaces are defined using the interface keyword, in the same way as a &#8230; <a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" class="more-link">Continue reading <span class="screen-reader-text">Some Notes on the Object-oriented Model of PHP</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/27/object-cloning-and-passing-by-reference-in-php/" rel="bookmark" title="Object Cloning and Passing by Reference in PHP">Object Cloning and Passing by Reference in PHP </a></li>
<li><a href="/2011/11/14/php-dont-call-the-destructor-explicitly/" rel="bookmark" title="PHP: Don&#8217;t Call the Destructor Explicitly">PHP: Don&#8217;t Call the Destructor Explicitly </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>PHP 5 introduces interfaces and abstract classes. To become a little clearer, let us see their definitions.</p>
<h2>Interfaces</h2>
<blockquote><p>Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.<br />
Interfaces are defined using the interface keyword, in the same way as a standard class, but without any of the methods having their contents defined.<br />
All methods declared in an interface must be public, this is the nature of an interface. </p>
<p>To implement an interface, the implements operator is used. All methods in the interface must be implemented within a class; failure to do so will result in a fatal error. Classes may implement more than one interface if desired by separating each interface with a comma. </p></blockquote>
<h2>Abstract Classes</h2>
<blockquote><p>PHP 5 introduces abstract classes and methods. Classes defined as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract. Methods defined as abstract simply declare the method&#8217;s signature &#8211; they cannot define the implementation.</p>
<p>When inheriting from an abstract class, all methods marked abstract in the parent&#8217;s class declaration must be defined by the child; additionally, these methods must be defined with the same (or a less restricted) visibility. For example, if the abstract method is defined as protected, the function implementation must be defined as either protected or public, but not private. Furthermore the signatures of the methods must match, i.e. the type hints and the number of required arguments must be the same. This also applies to constructors as of PHP 5.4. Before 5.4 constructor signatures could differ. </p></blockquote>
<h2>Some Cases</h2>
<p>Now let&#8217;s do a quick experiment. According to the definition of interfaces we can define an interface and than an abstract class can implement this interface.<br />
<span id="more-2401"></span></p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
}
</pre>
<p>However the abstract class cannot be instantiated so we need to extend it.</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
}

class C extends B
{
	...
}
</pre>
<p>In the first place is completely OK to define an abstract class that does not contain any abstract method. TUsually if a class has one or more abstract methods <em>(Methods defined as abstract simply declare the method&#8217;s signature &#8211; they cannot define the implementation, according to the docs)</em>, it must be defined as abstract. But we can also define an abstract class which has no abstract methods.</p>
<pre lang="PHP">
abstract class B
{
	public function a()
	{
		return 5;
	}
}

class C extends B
{
	public function a()
	{
		return 10;
	}
}

$c = new C();
echo $c->a();
</pre>
<p>OK then what would happen if we had an interface that is implemented by an abstract class, which in turn is extended by a given class. First of all if a class implements an interface, even if it is an abstract class, it must implement all methods defined in the interface. So if the predefined method in the abstract class is marked as abstract, it would result into a fatal error.</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	abstract public function a();
}

class C extends B
{
	public function a()
	{
		return 5;
	}
}

$c = new C();
echo $c->a();
</pre>
<p>This is perfectly logical, because in fact each method of the interface must be implemented by his children.</p>
<p><em>&#8220;All methods in the interface must be implemented within a class; failure to do so will result in a fatal error.&#8221;<br />
</em><br />
Fine, but we can have abstract classes with no abstract methods, let&#8217;s try this:</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
}

class C extends B
{
	public function a()
	{
		return 5;
	}
}

$c = new C();
echo $c->a();
</pre>
<p>This code is working and the result is the returned value from C::a(). However class B is abstract so let&#8217;s go even further. Let&#8217;s define an abstract method, different from the method B::a().</p>
<pre lang="PHP">
interface A
{
	public function a();
}

abstract class B implements A
{
	public function a()
	{
		return 10;
	}
	
	abstract public function b();
}

class C extends B
{
	public function a()
	{
		return 5;
	}
	
	public function b()
	{
		return "hello world!";
	}
}

$c = new C();
echo $c->a();
echo $c->b();
</pre>
<p>Now there&#8217;s a fatal error. Why?</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/27/object-cloning-and-passing-by-reference-in-php/" rel="bookmark" title="Object Cloning and Passing by Reference in PHP">Object Cloning and Passing by Reference in PHP </a></li>
<li><a href="/2011/11/14/php-dont-call-the-destructor-explicitly/" rel="bookmark" title="PHP: Don&#8217;t Call the Destructor Explicitly">PHP: Don&#8217;t Call the Destructor Explicitly </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/10/20/some-notes-on-the-object-oriented-model-of-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Object Oriented JavaScript: Inheritance</title>
		<link>/2011/05/30/object-oriented-javascript-inheritance/</link>
		<comments>/2011/05/30/object-oriented-javascript-inheritance/#comments</comments>
		<pubDate>Mon, 30 May 2011 09:43:53 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[code sample]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Literal]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[Object-oriented programming]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[oop javascript]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/?p=2314</guid>
		<description><![CDATA[Objects and JavaScript JavaScript, being a functional language, differs from most of the procedural/object oriented languages we know. The object oriented approach in JavaScript is rather strange. However there is much power in making objects! The syntax is really odd and there are several approaches. Literal Notation As many of you may know the most &#8230; <a href="/2011/05/30/object-oriented-javascript-inheritance/" class="more-link">Continue reading <span class="screen-reader-text">Object Oriented JavaScript: Inheritance</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/03/02/javascript-inheritance-example/" rel="bookmark" title="JavaScript inheritance example">JavaScript inheritance example </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Objects and JavaScript</h2>
<p><a href="/tag/javascript/" title="JavaScript on Stoimen.com">JavaScript</a>, being a functional language, differs from most of the procedural/object oriented languages we know. The object oriented approach in JavaScript is rather strange. However there is much power in making objects! The syntax is really odd and there are several approaches.</p>
<h2>Literal Notation</h2>
<p>As many of you may know the most used notation is the JSON (JavaScript Object Notation).</p>
<pre lang="javascript">
{ 'key1' : 'val1'
, 'key2' : 'val2'
, 'key3' : 'val3'
}
</pre>
<p>Of course this is the very basic example. You can use as value any JavaScript object &#8211; another similar object or a function.</p>
<pre lang="javascript">
{ 'key1' : 'val1'
, 'key2' : { 'inner_key1' : 'inner_val1' }
, 'key3' : function() {
			return 10 + 5;
		 }
}
</pre>
<p>The two examples above are showing an anonymous object in JavaScript, but you can assign this code to some variable.</p>
<pre lang="javascript">
var myObject = 
	{ 'key1' : 'val1'
	, 'key2' : 'val2'
	, 'key3' : 'val3'
	}
</pre>
<p>or </p>
<pre lang="javascript">
var myObject =
	{ 'key1' : 'val1'
	, 'key2' : { 'inner_key1' : 'inner_val1' }
	, 'key3' : function() {
				return 10 + 5;
			 }
	}
</pre>
<p>and then you can call the properties of these objects with the &#8216;.&#8217; operator:</p>
<pre lang="javascript">
myObject.key1;
myObject.key2.inner_key1;
myObject.key3();
</pre>
<p>So far so good &#8211; this is the literal object notation in JavaScript. However there is another &#8220;objects&#8221; in JavaScript.<br />
<span id="more-2314"></span></p>
<h2>Objects and Functions in JavaScript</h2>
<p>Actually in JS the functions are also objects (classes). So you can define a function and then define another function inside or use the &#8220;this&#8221; operator.</p>
<pre lang="javascript">
var a = function(name)
{
	this.name = name;
	
	this.print = function() {
		alert(this.name);	
	}
}
</pre>
<p>Then you can make a new instance of this &#8220;class&#8221;.</p>
<pre lang="javascript">
var myObject = new a('hello world');
var anotherObject = new a('some test');

myObject.print(); // will print the string "hello world"
anotherObject.print(); // will print the string "some test"
</pre>
<p>Thus the function <strong>&#8220;a&#8221;</strong> defined within the code <strong>&#8220;var a = function(name) &#8230;&#8221;</strong> is a class in JavaScript. You can make instances (objects) of this class with the &#8220;new&#8221; operator.</p>
<p>You can use another notation for defining the function &#8220;a&#8221;, so both can be used and it&#8217;s up to you to decide which one is more convenient.</p>
<pre lang="javascript">
function a(name) 
{
	this.name = name;
	
	this.print = function() {
		alert(this.name);	
	}	
}
</pre>
<h2>Prototypes</h2>
<p>JS gives you more power. In most of the languages you&#8217;ve to define the class first and then make objects. In JS you can define a &#8220;class&#8221; then make some objects and then add some properties to the class by using the prototype.</p>
<pre lang="javascript">
var a = function(name) 
{
	this.name = name;
}

var myObj = new a('hello world');

a.prototype.print = function() {
	alert(this.name);	
}

myObj.print();
</pre>
<p>So you can see how you can add functions and properties to an already defined class using the prototype. Thus you can call the &#8220;print&#8221; function on the myObj object.</p>
<h2>Inheritance</h2>
<p>The prototype built-in property can be used to make use of one of the main OOP features &#8211; inheritance. </p>
<pre lang="javascript">
var SuperClass = function()
{
	this.superFunction = function() {
		return 'function in Super Class';	
	}
}

var sup = new SuperClass();
sup.superFunction(); // will return the string "function in Super Class"
</pre>
<p>Now you can add one more class and set its prototype to the SuperClass</p>
<pre lang="javascript">
var SubClass = function()
{
	this.subFunction = function() {
		return 'function in Sub Class';	
	}	
}

SubClass.prototype = new SuperClass();
</pre>
<p>Thus you make SubClass inherit from SuperClass. Now you can call the SuperClass properties from any SubClass object.</p>
<pre lang="javascript">
var sub = new SubClass();
sub.superFunction(); // will return the string "function in Super Class"
sub.subFunction(); // will return the string "function in Sub Class"
</pre>
<p>Even more! You can add properties to the super class with prototype.</p>
<pre lang="javascript">
SuperClass.prototype.myFunc = function() {
	return 'my new function';	
}
</pre>
<p>And then call it from the sub class:</p>
<pre lang="javascript">
sub.myFunc(); // will return the string "my new function"
</pre>
<h2>Override a Function</h2>
<p>What happens if you have the same function name in both classes. Actually this overrides the method in the sub class.</p>
<pre lang="javascript">
var SuperClass = function()
{
	this.myFunc = function() {
		return 'function in Super Class';	
	}
}

var SubClass = function()
{
	this.myFunc = function() {
		return 'function in Sub Class';	
	}	
}

SubClass.prototype = new SuperClass();

var sub = new SubClass();
sub.myFunc(); // will return the string "function in Sub Class"
</pre>
<p>while </p>
<pre lang="javascript">
var sup = new SuperClass();
sup.myFunc(); // will return the string "function in Super Class"
</pre>
<h2>Conclusion</h2>
<p>Now you know there are classes, inheritance and overrides in JavaScript &#8211; thus you can improve your object oriented JavaScript!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/03/02/javascript-inheritance-example/" rel="bookmark" title="JavaScript inheritance example">JavaScript inheritance example </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/05/30/object-oriented-javascript-inheritance/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Models in Zend Framework &#8211; Initialize All Methods with init()</title>
		<link>/2010/08/09/models-in-zend-framework-initialize-all-methods-with-init/</link>
		<comments>/2010/08/09/models-in-zend-framework-initialize-all-methods-with-init/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 19:05:05 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[given controller]]></category>
		<category><![CDATA[Init]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web application frameworks]]></category>

		<guid isPermaLink="false">/?p=1890</guid>
		<description><![CDATA[In the Zend Framework&#8217;s documentation there are lots of examples how you can initialize all the actions in a given controller &#8211; by simply adding the init() public method in the controller&#8217;s code:<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/06/setting-up-zend-framework-with-modules/" rel="bookmark" title="Setting Up Zend Framework with Modules">Setting Up Zend Framework with Modules </a></li>
<li><a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" rel="bookmark" title="Bind Zend Action with Non-Default View &#8211; Part 2">Bind Zend Action with Non-Default View &#8211; Part 2 </a></li>
<li><a href="/2010/07/07/default-error-handling-in-zend-framework/" rel="bookmark" title="Default Error Handling in Zend Framework">Default Error Handling in Zend Framework </a></li>
<li><a href="/2010/07/06/zend-framework-simple-acl-front-controller-plugin/" rel="bookmark" title="Zend Framework: Simple Acl Front Controller Plugin">Zend Framework: Simple Acl Front Controller Plugin </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>In the Zend Framework&#8217;s documentation there are lots of examples how you can initialize all the actions in a given controller &#8211; by simply adding the init() public method in the controller&#8217;s code:</p>
<pre lang="php">
<?php

class IndexController extends Zend_Controller_Action
{
	public function init()
	{
		echo 'foo';	
	}	
	
	public function indexAction()
	{
		// first the 'foo' string will be printed
		echo 'bar';	
	}
}
</pre>
<p>But did you know that you can do the same thing with any model in ZF? However you can setup a cache for every method or something else, but definitely it will execute for every method:</p>
<pre lang="php">
<?php

class MyModel
{
	public function init()
	{
		// prepare the cache setup
	}	
	
	public function readAll()
	{
		// the cache is already setup
		$sql = '...';
		// ...
	}
}
</pre>
<p>Of course that means that directly calling the readAll() function the init() method is called also - automatically.</p>
<h2>Conclusion</h2>
<p>There are good and bad parts about this. You'll have this code executed for every method and if you have twenty of them and the init() method is practically used for only a couple of the member functions - than this will be useless.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/06/setting-up-zend-framework-with-modules/" rel="bookmark" title="Setting Up Zend Framework with Modules">Setting Up Zend Framework with Modules </a></li>
<li><a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" rel="bookmark" title="Bind Zend Action with Non-Default View &#8211; Part 2">Bind Zend Action with Non-Default View &#8211; Part 2 </a></li>
<li><a href="/2010/07/07/default-error-handling-in-zend-framework/" rel="bookmark" title="Default Error Handling in Zend Framework">Default Error Handling in Zend Framework </a></li>
<li><a href="/2010/07/06/zend-framework-simple-acl-front-controller-plugin/" rel="bookmark" title="Zend Framework: Simple Acl Front Controller Plugin">Zend Framework: Simple Acl Front Controller Plugin </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/09/models-in-zend-framework-initialize-all-methods-with-init/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
