<?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>PHPK.org &#187; LateStaticBinding</title>
	<atom:link href="http://www.phpk.org/archives/tag/latestaticbinding/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpk.org</link>
	<description>PHP User Group</description>
	<lastBuildDate>Tue, 17 Jan 2012 17:17:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>[PHP5.3.0] Late Static Bindings</title>
		<link>http://www.phpk.org/archives/301</link>
		<comments>http://www.phpk.org/archives/301#comments</comments>
		<pubDate>Wed, 15 Jul 2009 09:02:45 +0000</pubDate>
		<dc:creator>ooti</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[LateStaticBinding]]></category>
		<category><![CDATA[PHP5.3.0]]></category>
		<category><![CDATA[정적메소드]]></category>
		<category><![CDATA[정적함수]]></category>

		<guid isPermaLink="false">http://www.phpkorea.org/archives/301</guid>
		<description><![CDATA[같은 클래스 안에 속한 정적 함수를 호출 할 때에는 $this 변수를 사용하지 않고 self 키워드를 사용합니다. 이&#160; self 키워드의 특징은 self 를 실행하는 자기 클래스가 아니라 호출하려는 메소드가 정의된 클래스를 의미합니다. 1: &#60;?php 2: class ParentClass { 3: public static function who() { 4: echo 'I am Parent Class.'; 5: } 6: 7: public static [...]]]></description>
			<content:encoded><![CDATA[<p>같은 클래스 안에 속한 정적 함수를 호출 할 때에는 $this 변수를 사용하지 않고 self 키워드를 사용합니다. 이&#160; self 키워드의 특징은 self 를 실행하는 자기 클래스가 아니라 호출하려는 메소드가 정의된 클래스를 의미합니다.</p>
<pre style="border-right: #cecece 1px solid; padding-right: 5px; border-top: #cecece 1px solid; padding-left: 5px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #cecece 1px solid; width: 500px; padding-top: 5px; border-bottom: #cecece 1px solid; background-color: #fbfbfb">
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  1: <span style="color: #0000ff">&lt;?</span>php
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  2: <a style="color: #0000ff" href="http://www.php.net/class">class</a> ParentClass {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  3:   public static <a style="color: #0000ff" href="http://www.php.net/function">function</a> who() {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  4:     <a style="color: #0000ff" href="http://www.php.net/echo">echo</a> '<span style="color: #8b0000">I am Parent Class.</span>';
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  5:   }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  6:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  7:   public static <a style="color: #0000ff" href="http://www.php.net/function">function</a> whoAreYou() {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  8:     self::who();
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  9:   }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 10: }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 11:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 12: <a style="color: #0000ff" href="http://www.php.net/class">class</a> ChildClass <a style="color: #0000ff" href="http://www.php.net/extends">extends</a> ParentClass {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 13:   public static <a style="color: #0000ff" href="http://www.php.net/function">function</a> who() {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 14:     <a style="color: #0000ff" href="http://www.php.net/echo">echo</a> '<span style="color: #8b0000"> I am Child Class.</span>';
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 15:   }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 16: }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 17:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 18: ChildClass::whoAreYou();
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 19:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 20: <span style="color: #0000ff">?&gt;</span></pre>
</pre>
<p>위 코드와 같이 ChildClass 가 ParentClass 를 상속 받았습니다. ChildClass 에 있는 whoAreYour() 함수를 호출하여 who() 함수를 실행했을 때 어떤 문자열이 출력될까요.</p>
<p>결과는 I am Parent Class. 입니다.</p>
<p>정적 함수의 상속 관계를 그림으로 보면 아래와 같습니다.</p>
<p><a href="http://blog.phpkorea.org/files/20090715-135134.jpg"><img title="2009-07-15_135134" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="476" alt="2009-07-15_135134" src="http://blog.phpkorea.org/files/20090715-135134-thumb.jpg" width="404" border="0" /></a> </p>
<h3>Last Static Bindings</h3>
<p>PHP 5.3.0 에서 추가된 Late Static Bindings는 static 키워드를 추가하여 정의된 부모 클래스가 아니라 상속을 받은 자기 자신을 지징할 수 있도록 했습니다. 코드를 보면 아래와 같습니다.</p>
<pre style="border-right: #cecece 1px solid; padding-right: 5px; border-top: #cecece 1px solid; padding-left: 5px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #cecece 1px solid; width: 500px; padding-top: 5px; border-bottom: #cecece 1px solid; background-color: #fbfbfb">
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  1: <span style="color: #0000ff">&lt;?</span>php
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  2: <a style="color: #0000ff" href="http://www.php.net/class">class</a> ParentClass {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  3:   public static <a style="color: #0000ff" href="http://www.php.net/function">function</a> who() {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  4:     <a style="color: #0000ff" href="http://www.php.net/echo">echo</a> '<span style="color: #8b0000">I am Parent Class.</span>';
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  5:   }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  6:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  7:   public static <a style="color: #0000ff" href="http://www.php.net/function">function</a> whoAreYou() {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  8:     static::who();
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  9:   }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 10: }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 11:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 12: <a style="color: #0000ff" href="http://www.php.net/class">class</a> ChildClass <a style="color: #0000ff" href="http://www.php.net/extends">extends</a> ParentClass {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 13:   public static <a style="color: #0000ff" href="http://www.php.net/function">function</a> who() {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 14:     <a style="color: #0000ff" href="http://www.php.net/echo">echo</a> '<span style="color: #8b0000"> I am Child Class.</span>';
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 15:   }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 16: }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 17:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 18: ChildClass::whoAreYou();
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 19:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 20: <span style="color: #0000ff">?&gt;</span></pre>
</pre>
<p>바뀐 부분을 눈치 채셨나요? ParentClass 의 whoAreYou() 함수 안에서 self::who() 코드가&#160; static::who() 로 바뀌었습니다. 이렇게 static 키워드를 사용하면 상속 받은 자식 클래스에서 자신의 함수를 사용할 수 있습니다. 이 static 키워드를 사용하면 아래 코드처럼 작성할 수도 있습니다.</p>
<p>아래 코드에서는 ParentClass 에 who() 함수가 없습니다. 그럼에도 불구하고 ParentClass 에서 who() 를 호출하고 있습니다. 이런 경우 ChildClass 의 who() 가 호출 될 것이므로 ParentClass 에 who() 함수가 정의되어 있지 않아도 됩니다.</p>
<pre style="border-right: #cecece 1px solid; padding-right: 5px; border-top: #cecece 1px solid; padding-left: 5px; min-height: 40px; padding-bottom: 5px; overflow: auto; border-left: #cecece 1px solid; width: 500px; padding-top: 5px; border-bottom: #cecece 1px solid; background-color: #fbfbfb">
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  1: <span style="color: #0000ff">&lt;?</span>php
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  2: <a style="color: #0000ff" href="http://www.php.net/class">class</a> ParentClass {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  3:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  4:   public static <a style="color: #0000ff" href="http://www.php.net/function">function</a> whoAreYou() {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  5:     static::who();
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  6:   }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  7: }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  8:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb">  9: <a style="color: #0000ff" href="http://www.php.net/class">class</a> ChildClass <a style="color: #0000ff" href="http://www.php.net/extends">extends</a> ParentClass {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 10:   public static <a style="color: #0000ff" href="http://www.php.net/function">function</a> who() {
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 11:     <a style="color: #0000ff" href="http://www.php.net/echo">echo</a> '<span style="color: #8b0000"> I am Child Class.</span>';
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 12:   }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 13: }
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 14:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 15: ChildClass::whoAreYou();
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 16:
</pre>
<pre style="font-size: 11px; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; background-color: #fbfbfb"> 17: <span style="color: #0000ff">?&gt;</span></pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.phpk.org/archives/301/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  www.phpk.org/archives/tag/latestaticbinding/feed ) in 0.14769 seconds, on Feb 8th, 2012 at 8:36 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 8th, 2012 at 9:36 am UTC -->
