<?xml version="1.0"?>
<oembed><version>1.0</version><provider_name>Mark's Blog</provider_name><provider_url>https://dangnh.cf/vi</provider_url><author_name>admin</author_name><author_url>https://dangnh.cf/vi/author/admin/</author_url><title>Trait - Mixin in PHP?  - Mark's Blog</title><type>rich</type><width>600</width><height>338</height><html>&lt;blockquote class="wp-embedded-content" data-secret="OAPhN31r71"&gt;&lt;a href="https://dangnh.cf/vi/2018/06/01/trait-mixin-in-php/"&gt;Trait &#x2013; Mixin in PHP? &lt;p1&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;iframe sandbox="allow-scripts" security="restricted" src="https://dangnh.cf/vi/2018/06/01/trait-mixin-in-php/embed/#?secret=OAPhN31r71" width="600" height="338" title="&#x201C;Trait &#x2013; Mixin in PHP? &lt;p1&gt;&#x201D; &#x2014; Mark's Blog" data-secret="OAPhN31r71" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"&gt;&lt;/iframe&gt;&lt;script type="text/javascript"&gt;
/* &lt;![CDATA[ */
/*! This file is auto-generated */
!function(d,l){"use strict";l.querySelector&amp;&amp;d.addEventListener&amp;&amp;"undefined"!=typeof URL&amp;&amp;(d.wp=d.wp||{},d.wp.receiveEmbedMessage||(d.wp.receiveEmbedMessage=function(e){var t=e.data;if((t||t.secret||t.message||t.value)&amp;&amp;!/[^a-zA-Z0-9]/.test(t.secret)){for(var s,r,n,a=l.querySelectorAll('iframe[data-secret="'+t.secret+'"]'),o=l.querySelectorAll('blockquote[data-secret="'+t.secret+'"]'),c=new RegExp("^https?:$","i"),i=0;i&lt;o.length;i++)o[i].style.display="none";for(i=0;i&lt;a.length;i++)s=a[i],e.source===s.contentWindow&amp;&amp;(s.removeAttribute("style"),"height"===t.message?(1e3&lt;(r=parseInt(t.value,10))?r=1e3:~~r&lt;200&amp;&amp;(r=200),s.height=r):"link"===t.message&amp;&amp;(r=new URL(s.getAttribute("src")),n=new URL(t.value),c.test(n.protocol))&amp;&amp;n.host===r.host&amp;&amp;l.activeElement===s&amp;&amp;(d.top.location.href=t.value))}},d.addEventListener("message",d.wp.receiveEmbedMessage,!1),l.addEventListener("DOMContentLoaded",function(){for(var e,t,s=l.querySelectorAll("iframe.wp-embedded-content"),r=0;r&lt;s.length;r++)(t=(e=s[r]).getAttribute("data-secret"))||(t=Math.random().toString(36).substring(2,12),e.src+="#?secret="+t,e.setAttribute("data-secret",t)),e.contentWindow.postMessage({message:"ready",secret:t},"*")},!1)))}(window,document);
//# sourceURL=https://dangnh.cf/wp-includes/js/wp-embed.min.js
/* ]]&gt; */
&lt;/script&gt;</html><thumbnail_url>https://dangnh.cf/wp-content/uploads/2018/06/retro-background-3101430_960_720.jpg</thumbnail_url><thumbnail_width>960</thumbnail_width><thumbnail_height>540</thumbnail_height><description>Hi guys &#x1F642; Nh&#x1B0; c&#xE1;c b&#x1EA1;n c&#xF3; l&#x1EBD; &#x111;&#xE3; bi&#x1EBF;t, PHP l&#xE0; 1 ng&#xF4;n ng&#x1EEF; single inheritance, t&#x1EE9;c l&#xE0; n&#xF3; s&#x1EBD; c&#xF3; 1 s&#x1ED1; nh&#x1B0;&#x1EE3;c &#x111;i&#x1EC3;m nh&#x1B0;: M&#x1EA5;t th&#x1EDD;i gian &amp; c&#xF4;ng s&#x1EE9;c khi t&#xEC;m hi&#x1EC3;u/ch&#x1EA1;y h&#x1EC7; th&#x1ED1;ng. V&#xED; d&#x1EE5;: 1 class c&#xF3; 10 levels c&#xE1;c class cha, th&#xEC; v&#x1EC1; c&#x1A1; b&#x1EA3;n n&#xF3; s&#x1EBD; ph&#x1EA3;i ch&#x1EA1;y qua c&#x1EA3; 10 levels &#x111;&#xF3; &#x111;&#x1EC3; ch&#x1EA1;y 1 function m&#xE0; n&#xF3; th&#x1EEB;a k&#x1EBF; Class cha v&#xE0; class con b&#x1ECB; r&#xE0;ng bu&#x1ED9;c v&#x1EDB;i nhau. T&#x1EE9;c l&#xE0; ta kh&#xF4;ng th&#x1EC3; t&#xE1;ch ri&#xEA;ng bi&#x1EC7;t 1 class n&#xE0;o &#x111;&#x1EC3; s&#x1EED; d&#x1EE5;ng &#x111;&#x1B0;&#x1EE3;c. Theo th&#x1EDD;i gian, th&#xEA;m, s&#x1EED;a, x&#xF3;a c&#xE1;c ch&#x1EE9;c n&#x103;ng c&#x1EA7;n ph&#x1EA3;i r&#x1EA5;t c&#x1EA9;n th&#x1EAD;n, nhi&#x1EC1;u tr&#x1B0;&#x1EDD;ng h&#x1EE3;p l&#xE0; g&#x1EA7;n nh&#x1B0; kh&#xF4;ng th&#x1EC3; do &#x111;&#x1ED9; ph&#x1EE9;c t&#x1EA1;p c&#x1EE7;a c&#xE2;y th&#x1EEB;a k&#x1EBF; c&#xE1;c class &#x111;&#xF3;. C&#x1EF1;c k&#xEC; kh&#xF4;ng linh ho&#x1EA1;t trong nhi&#x1EC1;u tr&#x1B0;&#x1EDD;ng h&#x1EE3;p. V&#xED; d&#x1EE5; b&#x1EA1;n ch&#x1EC9; c&#x1EA7;n 1 class &#x111;&#x1A1;n gi&#x1EA3;n, ch&#x1EE9;a v&#xE0;i c&#xE1;i functions b&#x1EA1;n hay s&#x1EED; d&#x1EE5;ng trong h&#x1EC7; th&#x1ED1;ng, class n&#xE0;y c&#xF3; th&#x1EC3; d&#xED;nh d&#xE1;ng &#x111;&#x1EBF;n nhi&#x1EC1;u ph&#x1EA7;n kh&#xE1;c nhau trong h&#x1EC7; th&#x1ED1;ng, n&#xEA;n vi&#x1EC7;c th&#x1EEB;a k&#x1EBF; n&#xF3; c&#xF3; v&#x1EBB; s&#x1EBD; t&#x1EA1;o n&#xEA;n 1 n&#xFA;t xo&#x1EAF;n c&#x1EF1;c kh&#xF3; g&#x1EE1; trong c&#xE2;y th&#x1EEB;a k&#x1EBF; c&#xE1;c class. May m&#x1EAF;n thay, t&#x1EEB; PHP5.4, ch&#xFA;ng ta &#x111;&#xE3; c&#xF3;&#xA0;Trait &#x111;&#x1EC3; gi&#x1EA3;i quy&#x1EBF;t c&#xE1;c v&#x1EA5;n &#x111;&#x1EC1; n&#xF3;i tr&#xEA;n. Nh&#x1B0;ng li&#x1EC7;u Trait c&#xF3; ph&#x1EA3;i l&#xE0; Holy Grail cho PHP? Li&#x1EC7;u khi n&#xE0;o n&#xEA;n d&#xF9;ng Trait? Khi n&#xE0;o th&#xEC; ph&#x1EA3;i tr&#xE1;nh? M&#x1EDD;i c&#xE1;c b&#x1EA1;n k&#xE9;o xu&#x1ED1;ng d&#x1B0;&#x1EDB;i &#x111;&#x1EC3; t&#xEC;m hi&#x1EC3;u c&#xF9;ng m&#xEC;nh nh&#xE9; &#x1F609; Trait l&#xE0; g&#xEC;? Traits is a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies. Source &#x2026; okay&#x2026; h&#x1A1;i l&#x1EB1;ng nh&#x1EB1;ng ph&#x1EA3;i kh&#xF4;ng? Ng&#x1EAF;n g&#x1ECD;n th&#xEC; Trait c&#x169;ng gi&#x1ED1;ng nh&#x1B0; 1 abstract class v&#x1EAD;y. B&#x1EA1;n ch&#x1EE9;a c&#xE1;c methods, properties trong &#x111;&#xF3;, nh&#x1B0;ng b&#x1EA1;n kh&#xF4;ng th&#x1EC3; instantiate (t&#x1EA1;o object) n&#xF3; &#x111;&#x1B0;&#x1EE3;c. N&#xF3;i d&#x1EC5; hi&#x1EC3;u, Trait l&#xE0; 1 m&#x1EDB; code b&#x1EA1;n c&#xF3; th&#x1EC3; d&#xF9;ng b&#x1EA5;t c&#x1EE9; ch&#x1ED7; n&#xE0;o b&#x1EA1;n mu&#x1ED1;n. Simple as that &#x1F642; Nghe th&#xEC; &#x111;&#x1A1;n gi&#x1EA3;n th&#xF4;i nh&#x1B0;ng m&#xE0; h&#x1A1;i b&#x1ECB; hay &#x111;&#x1EA5;y. Next, l&#xE0;m n&#xE0;o &#x111;&#x1EC3; d&#xF9;ng Trait? Ph&#x1EA3;i cho v&#xED; d&#x1EE5; c&#x1EE5; th&#x1EC3; ng&#x1B0;&#x1EDD;i ta m&#x1EDB;i hi&#x1EC3;u &#x111;&#x1B0;&#x1EE3;c ch&#x1EE9;, &#x111;&#xFA;ng kh&#xF4;ng!? S&#x1EED; d&#x1EE5;ng Trait th&#x1EBF; n&#xE0;o? &#x1EDE; &#x111;&#xE2;y m&#xEC;nh s&#x1EBD; tr&#xEC;nh b&#xE0;y cho c&#xE1;c b&#x1EA1;n c&#xE1;ch s&#x1EED; d&#x1EE5;ng Trait trong r&#x1EA5;t nhi&#x1EC1;u tr&#x1B0;&#x1EDD;ng h&#x1EE3;p, c&#xF3; th&#x1EC3; s&#x1EBD; h&#x1A1;i d&#xE0;i, ch&#x1ECB;u kh&#xF3; &#x111;&#x1ECD;c nh&#xE9; &#x1F609; V&#xED; d&#x1EE5; &#x111;&#x1A1;n gi&#x1EA3;n: V&#x1EC1; quy&#x1EC1;n &#x1B0;u ti&#xEA;n, n&#x1EBF;u tr&#xF9;ng t&#xEA;n function c&#x1EE7;a Trait v&#x1EDB;i function c&#x1EE7;a Base class, th&#xEC; chuy&#x1EC7;n g&#xEC; s&#x1EBD; x&#x1EA3;y ra? To be continue&#x2026;</description></oembed>
