{"id":211,"date":"2018-06-01T14:45:31","date_gmt":"2018-06-01T06:45:31","guid":{"rendered":"https:\/\/dangnhsite.wordpress.com\/?p=211"},"modified":"2018-06-11T00:35:21","modified_gmt":"2018-06-10T16:35:21","slug":"trait-mixin-in-php","status":"publish","type":"post","link":"https:\/\/dangnh.cf\/vi\/2018\/06\/01\/trait-mixin-in-php\/","title":{"rendered":"Trait &#8211; Mixin in PHP? <p1>"},"content":{"rendered":"<p>Hi guys \ud83d\ude42<\/p>\n<p>Nh\u01b0 c\u00e1c b\u1ea1n c\u00f3 l\u1ebd \u0111\u00e3 bi\u1ebft, PHP l\u00e0 1 ng\u00f4n ng\u1eef single inheritance, t\u1ee9c l\u00e0 n\u00f3 s\u1ebd c\u00f3 1 s\u1ed1 nh\u01b0\u1ee3c \u0111i\u1ec3m nh\u01b0:<\/p>\n<ul>\n<li>M\u1ea5t th\u1eddi gian &amp; c\u00f4ng s\u1ee9c khi t\u00ecm hi\u1ec3u\/ch\u1ea1y h\u1ec7 th\u1ed1ng. V\u00ed d\u1ee5: 1 class c\u00f3 10 levels c\u00e1c class cha, th\u00ec v\u1ec1 c\u01a1 b\u1ea3n n\u00f3 s\u1ebd ph\u1ea3i ch\u1ea1y qua c\u1ea3 10 levels \u0111\u00f3 \u0111\u1ec3 ch\u1ea1y 1 function m\u00e0 n\u00f3 th\u1eeba k\u1ebf<\/li>\n<li>Class cha v\u00e0 class con b\u1ecb r\u00e0ng bu\u1ed9c v\u1edbi nhau. T\u1ee9c l\u00e0 ta kh\u00f4ng th\u1ec3 t\u00e1ch ri\u00eang bi\u1ec7t 1 class n\u00e0o \u0111\u1ec3 s\u1eed d\u1ee5ng \u0111\u01b0\u1ee3c.<\/li>\n<li>Theo th\u1eddi gian, th\u00eam, s\u1eeda, x\u00f3a c\u00e1c ch\u1ee9c n\u0103ng c\u1ea7n ph\u1ea3i r\u1ea5t c\u1ea9n th\u1eadn, nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p l\u00e0 g\u1ea7n nh\u01b0 kh\u00f4ng th\u1ec3 do \u0111\u1ed9 ph\u1ee9c t\u1ea1p c\u1ee7a c\u00e2y th\u1eeba k\u1ebf c\u00e1c class \u0111\u00f3.<\/li>\n<li>C\u1ef1c k\u00ec kh\u00f4ng linh ho\u1ea1t trong nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p. V\u00ed d\u1ee5 b\u1ea1n ch\u1ec9 c\u1ea7n 1 class \u0111\u01a1n gi\u1ea3n, ch\u1ee9a v\u00e0i c\u00e1i functions b\u1ea1n hay s\u1eed d\u1ee5ng trong h\u1ec7 th\u1ed1ng, class n\u00e0y c\u00f3 th\u1ec3 d\u00ednh d\u00e1ng \u0111\u1ebfn nhi\u1ec1u ph\u1ea7n kh\u00e1c nhau trong h\u1ec7 th\u1ed1ng, n\u00ean vi\u1ec7c th\u1eeba k\u1ebf n\u00f3 c\u00f3 v\u1ebb s\u1ebd t\u1ea1o n\u00ean 1 n\u00fat xo\u1eafn c\u1ef1c kh\u00f3 g\u1ee1 trong c\u00e2y th\u1eeba k\u1ebf c\u00e1c class.<\/li>\n<\/ul>\n<p>May m\u1eafn thay, t\u1eeb PHP5.4, ch\u00fang ta \u0111\u00e3 c\u00f3\u00a0<strong>Trait<\/strong> \u0111\u1ec3 gi\u1ea3i quy\u1ebft c\u00e1c v\u1ea5n \u0111\u1ec1 n\u00f3i tr\u00ean. Nh\u01b0ng li\u1ec7u Trait c\u00f3 ph\u1ea3i l\u00e0 Holy Grail cho PHP? Li\u1ec7u khi n\u00e0o n\u00ean d\u00f9ng Trait? Khi n\u00e0o th\u00ec ph\u1ea3i tr\u00e1nh? M\u1eddi c\u00e1c b\u1ea1n k\u00e9o xu\u1ed1ng d\u01b0\u1edbi \u0111\u1ec3 t\u00ecm hi\u1ec3u c\u00f9ng m\u00ecnh nh\u00e9 \ud83d\ude09<\/p>\n<ol>\n<li>\n<h3>Trait l\u00e0 g\u00ec?<\/h3>\n<\/li>\n<\/ol>\n<blockquote><p><span style=\"font-size: 16px;\">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.<\/span><\/p>\n<p style=\"text-align: right;\"><a href=\"http:\/\/php.net\/manual\/en\/language.oop5.traits.php\"><em>Source<\/em><\/a><\/p>\n<\/blockquote>\n<p style=\"text-align: center;\">&#8230; okay&#8230; h\u01a1i l\u1eb1ng nh\u1eb1ng ph\u1ea3i kh\u00f4ng?<\/p>\n<p>Ng\u1eafn g\u1ecdn th\u00ec Trait c\u0169ng gi\u1ed1ng nh\u01b0 1 <strong>abstract class<\/strong> v\u1eady. B\u1ea1n ch\u1ee9a c\u00e1c methods, properties trong \u0111\u00f3, nh\u01b0ng b\u1ea1n <strong>kh\u00f4ng th\u1ec3 instantiate<\/strong> (t\u1ea1o object) n\u00f3 \u0111\u01b0\u1ee3c.<\/p>\n<p>N\u00f3i d\u1ec5 hi\u1ec3u, Trait l\u00e0 1 m\u1edb code b\u1ea1n c\u00f3 th\u1ec3 d\u00f9ng b\u1ea5t c\u1ee9 ch\u1ed7 n\u00e0o b\u1ea1n mu\u1ed1n. Simple as that \ud83d\ude42<br \/>\nNghe th\u00ec \u0111\u01a1n gi\u1ea3n th\u00f4i nh\u01b0ng m\u00e0 h\u01a1i b\u1ecb hay \u0111\u1ea5y. Next, l\u00e0m n\u00e0o \u0111\u1ec3 d\u00f9ng Trait? Ph\u1ea3i cho v\u00ed d\u1ee5 c\u1ee5 th\u1ec3 ng\u01b0\u1eddi ta m\u1edbi hi\u1ec3u \u0111\u01b0\u1ee3c ch\u1ee9, \u0111\u00fang kh\u00f4ng!?<\/p>\n<ol start=\"2\">\n<li>\n<h3>S\u1eed d\u1ee5ng Trait th\u1ebf n\u00e0o?<\/h3>\n<\/li>\n<\/ol>\n<p>\u1ede \u0111\u00e2y m\u00ecnh s\u1ebd tr\u00ecnh b\u00e0y cho c\u00e1c b\u1ea1n c\u00e1ch s\u1eed d\u1ee5ng Trait trong r\u1ea5t nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p, c\u00f3 th\u1ec3 s\u1ebd h\u01a1i d\u00e0i, ch\u1ecbu kh\u00f3 \u0111\u1ecdc nh\u00e9 \ud83d\ude09<\/p>\n<ul>\n<li>V\u00ed d\u1ee5 \u0111\u01a1n gi\u1ea3n:<\/li>\n<\/ul>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n\r\n\/** \u0110\u1ecbnh ngh\u0129a 1 Trait **\/\r\ntrait ToolBox {\r\n    function hammer() {}\r\n    function dumpdie() {}\r\n} \r\n\r\n\/** S\u1eed d\u1ee5ng Trait **\/\r\nclass HotBabe {\r\n    use ToolBox; \/\/&quot;import&quot; trait\r\n    function doIt() {\r\n         hammer(); \/\/Use Trait's function\r\n    }\r\n}\r\n?&gt;\r\n<\/pre>\n<ul>\n<li>V\u1ec1 quy\u1ec1n \u01b0u ti\u00ean, n\u1ebfu tr\u00f9ng t\u00ean function c\u1ee7a Trait v\u1edbi function c\u1ee7a Base class, th\u00ec chuy\u1ec7n g\u00ec s\u1ebd x\u1ea3y ra?<\/li>\n<\/ul>\n<p>To be continue&#8230;<\/p>","protected":false},"excerpt":{"rendered":"<p>Hi guys \ud83d\ude42 Nh\u01b0 c\u00e1c b\u1ea1n c\u00f3 l\u1ebd \u0111\u00e3 bi\u1ebft, PHP l\u00e0 1 ng\u00f4n ng\u1eef single inheritance, t\u1ee9c l\u00e0 n\u00f3 s\u1ebd c\u00f3 1 s\u1ed1 nh\u01b0\u1ee3c \u0111i\u1ec3m nh\u01b0: M\u1ea5t th\u1eddi gian &amp; c\u00f4ng s\u1ee9c khi t\u00ecm hi\u1ec3u\/ch\u1ea1y h\u1ec7 th\u1ed1ng. V\u00ed d\u1ee5: 1 class c\u00f3 10 levels c\u00e1c class cha, th\u00ec v\u1ec1 c\u01a1 b\u1ea3n n\u00f3 s\u1ebd ph\u1ea3i ch\u1ea1y qua c\u1ea3 10 levels \u0111\u00f3 \u0111\u1ec3 ch\u1ea1y 1 function m\u00e0 n\u00f3 th\u1eeba k\u1ebf Class cha v\u00e0 class con b\u1ecb r\u00e0ng bu\u1ed9c v\u1edbi nhau. T\u1ee9c l\u00e0 ta kh\u00f4ng th\u1ec3 t\u00e1ch ri\u00eang bi\u1ec7t 1 class n\u00e0o \u0111\u1ec3 s\u1eed d\u1ee5ng \u0111\u01b0\u1ee3c. Theo th\u1eddi gian, th\u00eam, s\u1eeda, x\u00f3a c\u00e1c ch\u1ee9c n\u0103ng c\u1ea7n ph\u1ea3i r\u1ea5t c\u1ea9n th\u1eadn, nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p l\u00e0 g\u1ea7n nh\u01b0 kh\u00f4ng th\u1ec3 do \u0111\u1ed9 ph\u1ee9c t\u1ea1p c\u1ee7a c\u00e2y th\u1eeba k\u1ebf c\u00e1c class \u0111\u00f3. C\u1ef1c k\u00ec kh\u00f4ng linh ho\u1ea1t trong nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p. V\u00ed d\u1ee5 b\u1ea1n ch\u1ec9 c\u1ea7n 1 class \u0111\u01a1n gi\u1ea3n, ch\u1ee9a v\u00e0i c\u00e1i functions b\u1ea1n hay s\u1eed d\u1ee5ng trong h\u1ec7 th\u1ed1ng, class n\u00e0y c\u00f3 th\u1ec3 d\u00ednh d\u00e1ng \u0111\u1ebfn nhi\u1ec1u ph\u1ea7n kh\u00e1c nhau trong h\u1ec7 th\u1ed1ng, n\u00ean vi\u1ec7c th\u1eeba k\u1ebf n\u00f3 c\u00f3 v\u1ebb s\u1ebd t\u1ea1o n\u00ean 1 n\u00fat xo\u1eafn c\u1ef1c kh\u00f3 g\u1ee1 trong c\u00e2y th\u1eeba k\u1ebf c\u00e1c class. May m\u1eafn thay, t\u1eeb PHP5.4, ch\u00fang ta \u0111\u00e3 c\u00f3\u00a0Trait \u0111\u1ec3 gi\u1ea3i quy\u1ebft c\u00e1c v\u1ea5n \u0111\u1ec1 n\u00f3i tr\u00ean. Nh\u01b0ng li\u1ec7u Trait c\u00f3 ph\u1ea3i l\u00e0 Holy Grail cho PHP? Li\u1ec7u khi n\u00e0o n\u00ean d\u00f9ng Trait? Khi n\u00e0o th\u00ec ph\u1ea3i tr\u00e1nh? M\u1eddi c\u00e1c b\u1ea1n k\u00e9o xu\u1ed1ng d\u01b0\u1edbi \u0111\u1ec3 t\u00ecm hi\u1ec3u c\u00f9ng m\u00ecnh nh\u00e9 \ud83d\ude09 Trait l\u00e0 g\u00ec? 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 &#8230; okay&#8230; h\u01a1i l\u1eb1ng nh\u1eb1ng ph\u1ea3i kh\u00f4ng? Ng\u1eafn g\u1ecdn th\u00ec Trait c\u0169ng gi\u1ed1ng nh\u01b0 1 abstract class v\u1eady. B\u1ea1n ch\u1ee9a c\u00e1c methods, properties trong \u0111\u00f3, nh\u01b0ng b\u1ea1n kh\u00f4ng th\u1ec3 instantiate (t\u1ea1o object) n\u00f3 \u0111\u01b0\u1ee3c. N\u00f3i d\u1ec5 hi\u1ec3u, Trait l\u00e0 1 m\u1edb code b\u1ea1n c\u00f3 th\u1ec3 d\u00f9ng b\u1ea5t c\u1ee9 ch\u1ed7 n\u00e0o b\u1ea1n mu\u1ed1n. Simple as that \ud83d\ude42 Nghe th\u00ec \u0111\u01a1n gi\u1ea3n th\u00f4i nh\u01b0ng m\u00e0 h\u01a1i b\u1ecb hay \u0111\u1ea5y. Next, l\u00e0m n\u00e0o \u0111\u1ec3 d\u00f9ng Trait? Ph\u1ea3i cho v\u00ed d\u1ee5 c\u1ee5 th\u1ec3 ng\u01b0\u1eddi ta m\u1edbi hi\u1ec3u \u0111\u01b0\u1ee3c ch\u1ee9, \u0111\u00fang kh\u00f4ng!? S\u1eed d\u1ee5ng Trait th\u1ebf n\u00e0o? \u1ede \u0111\u00e2y m\u00ecnh s\u1ebd tr\u00ecnh b\u00e0y cho c\u00e1c b\u1ea1n c\u00e1ch s\u1eed d\u1ee5ng Trait trong r\u1ea5t nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p, c\u00f3 th\u1ec3 s\u1ebd h\u01a1i d\u00e0i, ch\u1ecbu kh\u00f3 \u0111\u1ecdc nh\u00e9 \ud83d\ude09 V\u00ed d\u1ee5 \u0111\u01a1n gi\u1ea3n: &lt;?php \/** \u0110\u1ecbnh ngh\u0129a 1 Trait **\/ trait ToolBox { function hammer() {} function dumpdie() {} } \/** S\u1eed d\u1ee5ng Trait **\/ class HotBabe { use ToolBox; \/\/&quot;import&quot; trait function doIt() { hammer(); \/\/Use Trait&#8217;s function } } ?&gt; V\u1ec1 quy\u1ec1n \u01b0u ti\u00ean, n\u1ebfu tr\u00f9ng t\u00ean function c\u1ee7a Trait v\u1edbi function c\u1ee7a Base class, th\u00ec chuy\u1ec7n g\u00ec s\u1ebd x\u1ea3y ra? To be continue&#8230;<\/p>","protected":false},"author":1,"featured_media":349,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5,3],"tags":[16,15,17],"class_list":["post-211","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-web-development","tag-architecture","tag-php","tag-trait"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Trait - Mixin in PHP?  - Mark&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dangnh.cf\/vi\/2018\/06\/01\/trait-mixin-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Trait - Mixin in PHP?  - Mark&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"Hi guys \ud83d\ude42 Nh\u01b0 c\u00e1c b\u1ea1n c\u00f3 l\u1ebd \u0111\u00e3 bi\u1ebft, PHP l\u00e0 1 ng\u00f4n ng\u1eef single inheritance, t\u1ee9c l\u00e0 n\u00f3 s\u1ebd c\u00f3 1 s\u1ed1 nh\u01b0\u1ee3c \u0111i\u1ec3m nh\u01b0: M\u1ea5t th\u1eddi gian &amp; c\u00f4ng s\u1ee9c khi t\u00ecm hi\u1ec3u\/ch\u1ea1y h\u1ec7 th\u1ed1ng. V\u00ed d\u1ee5: 1 class c\u00f3 10 levels c\u00e1c class cha, th\u00ec v\u1ec1 c\u01a1 b\u1ea3n n\u00f3 s\u1ebd ph\u1ea3i ch\u1ea1y qua c\u1ea3 10 levels \u0111\u00f3 \u0111\u1ec3 ch\u1ea1y 1 function m\u00e0 n\u00f3 th\u1eeba k\u1ebf Class cha v\u00e0 class con b\u1ecb r\u00e0ng bu\u1ed9c v\u1edbi nhau. T\u1ee9c l\u00e0 ta kh\u00f4ng th\u1ec3 t\u00e1ch ri\u00eang bi\u1ec7t 1 class n\u00e0o \u0111\u1ec3 s\u1eed d\u1ee5ng \u0111\u01b0\u1ee3c. Theo th\u1eddi gian, th\u00eam, s\u1eeda, x\u00f3a c\u00e1c ch\u1ee9c n\u0103ng c\u1ea7n ph\u1ea3i r\u1ea5t c\u1ea9n th\u1eadn, nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p l\u00e0 g\u1ea7n nh\u01b0 kh\u00f4ng th\u1ec3 do \u0111\u1ed9 ph\u1ee9c t\u1ea1p c\u1ee7a c\u00e2y th\u1eeba k\u1ebf c\u00e1c class \u0111\u00f3. C\u1ef1c k\u00ec kh\u00f4ng linh ho\u1ea1t trong nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p. V\u00ed d\u1ee5 b\u1ea1n ch\u1ec9 c\u1ea7n 1 class \u0111\u01a1n gi\u1ea3n, ch\u1ee9a v\u00e0i c\u00e1i functions b\u1ea1n hay s\u1eed d\u1ee5ng trong h\u1ec7 th\u1ed1ng, class n\u00e0y c\u00f3 th\u1ec3 d\u00ednh d\u00e1ng \u0111\u1ebfn nhi\u1ec1u ph\u1ea7n kh\u00e1c nhau trong h\u1ec7 th\u1ed1ng, n\u00ean vi\u1ec7c th\u1eeba k\u1ebf n\u00f3 c\u00f3 v\u1ebb s\u1ebd t\u1ea1o n\u00ean 1 n\u00fat xo\u1eafn c\u1ef1c kh\u00f3 g\u1ee1 trong c\u00e2y th\u1eeba k\u1ebf c\u00e1c class. May m\u1eafn thay, t\u1eeb PHP5.4, ch\u00fang ta \u0111\u00e3 c\u00f3\u00a0Trait \u0111\u1ec3 gi\u1ea3i quy\u1ebft c\u00e1c v\u1ea5n \u0111\u1ec1 n\u00f3i tr\u00ean. Nh\u01b0ng li\u1ec7u Trait c\u00f3 ph\u1ea3i l\u00e0 Holy Grail cho PHP? Li\u1ec7u khi n\u00e0o n\u00ean d\u00f9ng Trait? Khi n\u00e0o th\u00ec ph\u1ea3i tr\u00e1nh? M\u1eddi c\u00e1c b\u1ea1n k\u00e9o xu\u1ed1ng d\u01b0\u1edbi \u0111\u1ec3 t\u00ecm hi\u1ec3u c\u00f9ng m\u00ecnh nh\u00e9 \ud83d\ude09 Trait l\u00e0 g\u00ec? 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 &#8230; okay&#8230; h\u01a1i l\u1eb1ng nh\u1eb1ng ph\u1ea3i kh\u00f4ng? Ng\u1eafn g\u1ecdn th\u00ec Trait c\u0169ng gi\u1ed1ng nh\u01b0 1 abstract class v\u1eady. B\u1ea1n ch\u1ee9a c\u00e1c methods, properties trong \u0111\u00f3, nh\u01b0ng b\u1ea1n kh\u00f4ng th\u1ec3 instantiate (t\u1ea1o object) n\u00f3 \u0111\u01b0\u1ee3c. N\u00f3i d\u1ec5 hi\u1ec3u, Trait l\u00e0 1 m\u1edb code b\u1ea1n c\u00f3 th\u1ec3 d\u00f9ng b\u1ea5t c\u1ee9 ch\u1ed7 n\u00e0o b\u1ea1n mu\u1ed1n. Simple as that \ud83d\ude42 Nghe th\u00ec \u0111\u01a1n gi\u1ea3n th\u00f4i nh\u01b0ng m\u00e0 h\u01a1i b\u1ecb hay \u0111\u1ea5y. Next, l\u00e0m n\u00e0o \u0111\u1ec3 d\u00f9ng Trait? Ph\u1ea3i cho v\u00ed d\u1ee5 c\u1ee5 th\u1ec3 ng\u01b0\u1eddi ta m\u1edbi hi\u1ec3u \u0111\u01b0\u1ee3c ch\u1ee9, \u0111\u00fang kh\u00f4ng!? S\u1eed d\u1ee5ng Trait th\u1ebf n\u00e0o? \u1ede \u0111\u00e2y m\u00ecnh s\u1ebd tr\u00ecnh b\u00e0y cho c\u00e1c b\u1ea1n c\u00e1ch s\u1eed d\u1ee5ng Trait trong r\u1ea5t nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p, c\u00f3 th\u1ec3 s\u1ebd h\u01a1i d\u00e0i, ch\u1ecbu kh\u00f3 \u0111\u1ecdc nh\u00e9 \ud83d\ude09 V\u00ed d\u1ee5 \u0111\u01a1n gi\u1ea3n: &lt;?php \/** \u0110\u1ecbnh ngh\u0129a 1 Trait **\/ trait ToolBox { function hammer() {} function dumpdie() {} } \/** S\u1eed d\u1ee5ng Trait **\/ class HotBabe { use ToolBox; \/\/&quot;import&quot; trait function doIt() { hammer(); \/\/Use Trait&#039;s function } } ?&gt; V\u1ec1 quy\u1ec1n \u01b0u ti\u00ean, n\u1ebfu tr\u00f9ng t\u00ean function c\u1ee7a Trait v\u1edbi function c\u1ee7a Base class, th\u00ec chuy\u1ec7n g\u00ec s\u1ebd x\u1ea3y ra? To be continue&#8230;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dangnh.cf\/vi\/2018\/06\/01\/trait-mixin-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Mark&#039;s Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/dangtute\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-01T06:45:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-10T16:35:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 ph\u00fat\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/#\\\/schema\\\/person\\\/8f3b9db3b250186af217fbeec88eda9c\"},\"headline\":\"Trait &#8211; Mixin in PHP?\",\"datePublished\":\"2018-06-01T06:45:31+00:00\",\"dateModified\":\"2018-06-10T16:35:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/\"},\"wordCount\":632,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/dangnh.cf\\\/wp-content\\\/uploads\\\/2018\\\/06\\\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1\",\"keywords\":[\"architecture\",\"php\",\"trait\"],\"articleSection\":[\"PHP\",\"Web development\"],\"inLanguage\":\"vi\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/\",\"url\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/\",\"name\":\"Trait - Mixin in PHP? - Mark's Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/dangnh.cf\\\/wp-content\\\/uploads\\\/2018\\\/06\\\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1\",\"datePublished\":\"2018-06-01T06:45:31+00:00\",\"dateModified\":\"2018-06-10T16:35:21+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/#\\\/schema\\\/person\\\/8f3b9db3b250186af217fbeec88eda9c\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/#breadcrumb\"},\"inLanguage\":\"vi\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"vi\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/dangnh.cf\\\/wp-content\\\/uploads\\\/2018\\\/06\\\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/dangnh.cf\\\/wp-content\\\/uploads\\\/2018\\\/06\\\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1\",\"width\":960,\"height\":540,\"caption\":\"Trait in PHP\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/dangnh.cf\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Trait &#8211; Mixin in PHP?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/#website\",\"url\":\"https:\\\/\\\/dangnh.cf\\\/\",\"name\":\"Mark's Blog\",\"description\":\"A blog about Programming and Technical Stuffs\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/dangnh.cf\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"vi\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/#\\\/schema\\\/person\\\/8f3b9db3b250186af217fbeec88eda9c\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"vi\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g\",\"caption\":\"admin\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Trait - Mixin in PHP?  - Mark's Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dangnh.cf\/vi\/2018\/06\/01\/trait-mixin-in-php\/","og_locale":"vi_VN","og_type":"article","og_title":"Trait - Mixin in PHP?  - Mark's Blog","og_description":"Hi guys \ud83d\ude42 Nh\u01b0 c\u00e1c b\u1ea1n c\u00f3 l\u1ebd \u0111\u00e3 bi\u1ebft, PHP l\u00e0 1 ng\u00f4n ng\u1eef single inheritance, t\u1ee9c l\u00e0 n\u00f3 s\u1ebd c\u00f3 1 s\u1ed1 nh\u01b0\u1ee3c \u0111i\u1ec3m nh\u01b0: M\u1ea5t th\u1eddi gian &amp; c\u00f4ng s\u1ee9c khi t\u00ecm hi\u1ec3u\/ch\u1ea1y h\u1ec7 th\u1ed1ng. V\u00ed d\u1ee5: 1 class c\u00f3 10 levels c\u00e1c class cha, th\u00ec v\u1ec1 c\u01a1 b\u1ea3n n\u00f3 s\u1ebd ph\u1ea3i ch\u1ea1y qua c\u1ea3 10 levels \u0111\u00f3 \u0111\u1ec3 ch\u1ea1y 1 function m\u00e0 n\u00f3 th\u1eeba k\u1ebf Class cha v\u00e0 class con b\u1ecb r\u00e0ng bu\u1ed9c v\u1edbi nhau. T\u1ee9c l\u00e0 ta kh\u00f4ng th\u1ec3 t\u00e1ch ri\u00eang bi\u1ec7t 1 class n\u00e0o \u0111\u1ec3 s\u1eed d\u1ee5ng \u0111\u01b0\u1ee3c. Theo th\u1eddi gian, th\u00eam, s\u1eeda, x\u00f3a c\u00e1c ch\u1ee9c n\u0103ng c\u1ea7n ph\u1ea3i r\u1ea5t c\u1ea9n th\u1eadn, nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p l\u00e0 g\u1ea7n nh\u01b0 kh\u00f4ng th\u1ec3 do \u0111\u1ed9 ph\u1ee9c t\u1ea1p c\u1ee7a c\u00e2y th\u1eeba k\u1ebf c\u00e1c class \u0111\u00f3. C\u1ef1c k\u00ec kh\u00f4ng linh ho\u1ea1t trong nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p. V\u00ed d\u1ee5 b\u1ea1n ch\u1ec9 c\u1ea7n 1 class \u0111\u01a1n gi\u1ea3n, ch\u1ee9a v\u00e0i c\u00e1i functions b\u1ea1n hay s\u1eed d\u1ee5ng trong h\u1ec7 th\u1ed1ng, class n\u00e0y c\u00f3 th\u1ec3 d\u00ednh d\u00e1ng \u0111\u1ebfn nhi\u1ec1u ph\u1ea7n kh\u00e1c nhau trong h\u1ec7 th\u1ed1ng, n\u00ean vi\u1ec7c th\u1eeba k\u1ebf n\u00f3 c\u00f3 v\u1ebb s\u1ebd t\u1ea1o n\u00ean 1 n\u00fat xo\u1eafn c\u1ef1c kh\u00f3 g\u1ee1 trong c\u00e2y th\u1eeba k\u1ebf c\u00e1c class. May m\u1eafn thay, t\u1eeb PHP5.4, ch\u00fang ta \u0111\u00e3 c\u00f3\u00a0Trait \u0111\u1ec3 gi\u1ea3i quy\u1ebft c\u00e1c v\u1ea5n \u0111\u1ec1 n\u00f3i tr\u00ean. Nh\u01b0ng li\u1ec7u Trait c\u00f3 ph\u1ea3i l\u00e0 Holy Grail cho PHP? Li\u1ec7u khi n\u00e0o n\u00ean d\u00f9ng Trait? Khi n\u00e0o th\u00ec ph\u1ea3i tr\u00e1nh? M\u1eddi c\u00e1c b\u1ea1n k\u00e9o xu\u1ed1ng d\u01b0\u1edbi \u0111\u1ec3 t\u00ecm hi\u1ec3u c\u00f9ng m\u00ecnh nh\u00e9 \ud83d\ude09 Trait l\u00e0 g\u00ec? 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 &#8230; okay&#8230; h\u01a1i l\u1eb1ng nh\u1eb1ng ph\u1ea3i kh\u00f4ng? Ng\u1eafn g\u1ecdn th\u00ec Trait c\u0169ng gi\u1ed1ng nh\u01b0 1 abstract class v\u1eady. B\u1ea1n ch\u1ee9a c\u00e1c methods, properties trong \u0111\u00f3, nh\u01b0ng b\u1ea1n kh\u00f4ng th\u1ec3 instantiate (t\u1ea1o object) n\u00f3 \u0111\u01b0\u1ee3c. N\u00f3i d\u1ec5 hi\u1ec3u, Trait l\u00e0 1 m\u1edb code b\u1ea1n c\u00f3 th\u1ec3 d\u00f9ng b\u1ea5t c\u1ee9 ch\u1ed7 n\u00e0o b\u1ea1n mu\u1ed1n. Simple as that \ud83d\ude42 Nghe th\u00ec \u0111\u01a1n gi\u1ea3n th\u00f4i nh\u01b0ng m\u00e0 h\u01a1i b\u1ecb hay \u0111\u1ea5y. Next, l\u00e0m n\u00e0o \u0111\u1ec3 d\u00f9ng Trait? Ph\u1ea3i cho v\u00ed d\u1ee5 c\u1ee5 th\u1ec3 ng\u01b0\u1eddi ta m\u1edbi hi\u1ec3u \u0111\u01b0\u1ee3c ch\u1ee9, \u0111\u00fang kh\u00f4ng!? S\u1eed d\u1ee5ng Trait th\u1ebf n\u00e0o? \u1ede \u0111\u00e2y m\u00ecnh s\u1ebd tr\u00ecnh b\u00e0y cho c\u00e1c b\u1ea1n c\u00e1ch s\u1eed d\u1ee5ng Trait trong r\u1ea5t nhi\u1ec1u tr\u01b0\u1eddng h\u1ee3p, c\u00f3 th\u1ec3 s\u1ebd h\u01a1i d\u00e0i, ch\u1ecbu kh\u00f3 \u0111\u1ecdc nh\u00e9 \ud83d\ude09 V\u00ed d\u1ee5 \u0111\u01a1n gi\u1ea3n: &lt;?php \/** \u0110\u1ecbnh ngh\u0129a 1 Trait **\/ trait ToolBox { function hammer() {} function dumpdie() {} } \/** S\u1eed d\u1ee5ng Trait **\/ class HotBabe { use ToolBox; \/\/&quot;import&quot; trait function doIt() { hammer(); \/\/Use Trait's function } } ?&gt; V\u1ec1 quy\u1ec1n \u01b0u ti\u00ean, n\u1ebfu tr\u00f9ng t\u00ean function c\u1ee7a Trait v\u1edbi function c\u1ee7a Base class, th\u00ec chuy\u1ec7n g\u00ec s\u1ebd x\u1ea3y ra? To be continue&#8230;","og_url":"https:\/\/dangnh.cf\/vi\/2018\/06\/01\/trait-mixin-in-php\/","og_site_name":"Mark's Blog","article_publisher":"https:\/\/www.facebook.com\/dangtute","article_published_time":"2018-06-01T06:45:31+00:00","article_modified_time":"2018-06-10T16:35:21+00:00","og_image":[{"width":960,"height":540,"url":"https:\/\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg","type":"image\/jpeg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"admin","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"3 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/#article","isPartOf":{"@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/"},"author":{"name":"admin","@id":"https:\/\/dangnh.cf\/#\/schema\/person\/8f3b9db3b250186af217fbeec88eda9c"},"headline":"Trait &#8211; Mixin in PHP?","datePublished":"2018-06-01T06:45:31+00:00","dateModified":"2018-06-10T16:35:21+00:00","mainEntityOfPage":{"@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/"},"wordCount":632,"commentCount":0,"image":{"@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1","keywords":["architecture","php","trait"],"articleSection":["PHP","Web development"],"inLanguage":"vi","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/","url":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/","name":"Trait - Mixin in PHP? - Mark's Blog","isPartOf":{"@id":"https:\/\/dangnh.cf\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/#primaryimage"},"image":{"@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1","datePublished":"2018-06-01T06:45:31+00:00","dateModified":"2018-06-10T16:35:21+00:00","author":{"@id":"https:\/\/dangnh.cf\/#\/schema\/person\/8f3b9db3b250186af217fbeec88eda9c"},"breadcrumb":{"@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/#primaryimage","url":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1","contentUrl":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1","width":960,"height":540,"caption":"Trait in PHP"},{"@type":"BreadcrumbList","@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dangnh.cf\/"},{"@type":"ListItem","position":2,"name":"Trait &#8211; Mixin in PHP?"}]},{"@type":"WebSite","@id":"https:\/\/dangnh.cf\/#website","url":"https:\/\/dangnh.cf\/","name":"Mark's Blog","description":"A blog about Programming and Technical Stuffs","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dangnh.cf\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Person","@id":"https:\/\/dangnh.cf\/#\/schema\/person\/8f3b9db3b250186af217fbeec88eda9c","name":"admin","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/secure.gravatar.com\/avatar\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d838feab6bbd5e774c608b656a29ab0d54981b88fa4b563a83d7635108b6c76e?s=96&d=retro&r=g","caption":"admin"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9w3NP-3p","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":124,"url":"https:\/\/dangnh.cf\/vi\/2017\/05\/25\/stdclass-la-gi-lam-the-nao-de-co-properties-dong-trong-php\/","url_meta":{"origin":211,"position":0},"title":"stdClass l\u00e0 g\u00ec? L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 c\u00f3 Dynamic Properties trong PHP?","author":"admin","date":"Th\u00e1ng 5 25, 2017","format":false,"excerpt":"Ch\u00e0o c\u00e1c b\u1ea1n, m\u00ecnh l\u00e0 \u0110\u0103ng, v\u00e0 m\u00ecnh \u0111\u00e3 tr\u1edf l\u1ea1i r\u1ed3i \u0111\u00e2yy\u00a0 N\u1ebfu b\u1ea1n l\u00e0 1 ng\u01b0\u1eddi r\u1ea5t hay t\u00f2 m\u00f2 ngh\u1ecbch ng\u1ee3m, gi\u1ed1ng t\u00f4i, th\u00ec ch\u1eafc h\u1eb3n b\u1ea1n \u0111\u00e3 t\u1eebng lang thang trong core c\u1ee7a m\u1ea5y th\u1eb1ng PHP framework nh\u01b0 Laravel hay Yii, v\u00e0 ch\u1eafc cmn c\u00fa l\u00e0\u2026","rel":"","context":"Trong &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/dangnh.cf\/vi\/category\/web-development\/php\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/stdclass-trong-php.png?fit=365%2C268&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":367,"url":"https:\/\/dangnh.cf\/vi\/2020\/01\/20\/service-container-di-sanh-dieu-voi-laravel\/","url_meta":{"origin":211,"position":1},"title":"Service Container &#038; DI &#8220;s\u00e0nh \u0111i\u1ec7u&#8221; v\u1edbi Laravel","author":"admin","date":"Th\u00e1ng 1 20, 2020","format":false,"excerpt":"Hi, long time no see :D Laravel l\u00e0 m\u1ed9t framework n\u1ed5i ti\u1ebfng nh\u1ea5t trong c\u1ed9ng \u0111\u1ed3ng PHP, 1 ph\u1ea7n l\u00e0 v\u00ec c\u1ea5u tr\u00fac tuy\u1ec7t v\u1eddi c\u1ee7a n\u00f3. Khi n\u00f3i \u0111\u1ebfn architectural concepts c\u1ee7a Laravel, kh\u00f4ng th\u1ec3 kh\u00f4ng nh\u1eafc t\u1edbi Service Container. Khi b\u1ea1n \u0111\u1ee5ng \u0111\u1ebfn 1 b\u00e0i to\u00e1n l\u1edbn h\u01a1n,\u2026","rel":"","context":"Trong &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/dangnh.cf\/vi\/category\/web-development\/php\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2020\/01\/1_SstfI6yiEWj1mrnFrLTUdA-e1579505803935.jpeg?fit=900%2C600&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2020\/01\/1_SstfI6yiEWj1mrnFrLTUdA-e1579505803935.jpeg?fit=900%2C600&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2020\/01\/1_SstfI6yiEWj1mrnFrLTUdA-e1579505803935.jpeg?fit=900%2C600&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2020\/01\/1_SstfI6yiEWj1mrnFrLTUdA-e1579505803935.jpeg?fit=900%2C600&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":409,"url":"https:\/\/dangnh.cf\/vi\/2025\/05\/19\/huong-dan-setup-ai-blog-to-podcast-agent\/","url_meta":{"origin":211,"position":2},"title":"H\u01b0\u1edbng D\u1eabn Setup AI Blog to Podcast Agent","author":"admin","date":"Th\u00e1ng 5 19, 2025","format":false,"excerpt":"D\u01b0\u1edbi \u0111\u00e2y l\u00e0 b\u00e0i vi\u1ebft gi\u1edbi thi\u1ec7u nhanh v\u1ec1 repo Awesome LLM Apps v\u00e0 h\u01b0\u1edbng d\u1eabn ch\u1ea1y th\u1eed \u201cAI Blog to Podcast Agent\u201d tr\u00ean m\u00e1y Mac c\u1ee7a b\u1ea1n. M\u00ecnh s\u1ebd l\u1ea7n l\u01b0\u1ee3t \u0111i qua: Gi\u1edbi thi\u1ec7u chung v\u1ec1 repo T\u1ea1i sao n\u00ean kh\u00e1m ph\u00e1 \u0110i\u1ec3m nh\u1ea5n \u201cAI Blog to Podcast\u2026","rel":"","context":"Trong &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/dangnh.cf\/vi\/category\/ai\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/05\/ai-agent.png?fit=1024%2C1024&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/05\/ai-agent.png?fit=1024%2C1024&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/05\/ai-agent.png?fit=1024%2C1024&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/05\/ai-agent.png?fit=1024%2C1024&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":441,"url":"https:\/\/dangnh.cf\/vi\/2025\/06\/06\/rag-la-gi-va-tai-sao-may-ong-ai-cu-nhac-hoai\/","url_meta":{"origin":211,"position":3},"title":"RAG l\u00e0 g\u00ec? V\u00e0 t\u1ea1i sao m\u1ea5y \u00f4ng AI c\u1ee9 nh\u1eafc ho\u00e0i?","author":"admin","date":"Th\u00e1ng 6 6, 2025","format":false,"excerpt":"RAG \u2013 vi\u1ebft t\u1eaft c\u1ee7a \u201cRetrieval-Augmented Generation\u201d \u2013 nghe th\u00ec c\u00f3 v\u1ebb ng\u1ea7u, nh\u01b0ng th\u1ef1c ra hi\u1ec3u \u0111\u01a1n gi\u1ea3n th\u00ec n\u00f3 l\u00e0 m\u1ed9t c\u00e1ch gi\u00fap m\u1ea5y con AI\u2026 \u0111\u1ee1 ngu h\u01a1n khi tr\u1ea3 l\u1eddi c\u00e2u h\u1ecfi. N\u1ebfu b\u1ea1n \u0111\u00e3 s\u1eed d\u1ee5ng AI cho c\u00f4ng vi\u1ec7c chuy\u00ean m\u00f4n, ch\u1eafc ch\u1eafn c\u00f3\u2026","rel":"","context":"Trong &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/dangnh.cf\/vi\/category\/ai\/"},"img":{"alt_text":"RAG trong AI","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/06\/ai-rag.png?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/06\/ai-rag.png?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/06\/ai-rag.png?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/06\/ai-rag.png?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/06\/ai-rag.png?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":473,"url":"https:\/\/dangnh.cf\/vi\/2025\/11\/05\/ban-dung-cho-developer\/","url_meta":{"origin":211,"position":4},"title":"Standing desk &#8211; V\u1eadt trang tr\u00ed \u0111\u1eaft ti\u1ec1n hay m\u1eb9o hack productivity?","author":"admin","date":"Th\u00e1ng m\u01b0\u1eddi m\u1ed9t 5, 2025","format":false,"excerpt":"Mua c\u00e1i b\u00e0n \u0111\u1ee9ng - standing desk, t\u00f4i t\u01b0\u1edfng m\u00ecnh s\u1ebd th\u00e0nh si\u00eau nh\u00e2n. Ng\u01b0\u1eddi ta qu\u1ea3ng c\u00e1o b\u1ea3o \u0111\u1ee9ng l\u00e0m vi\u1ec7c s\u1ebd t\u1eadp trung h\u01a1n, kh\u1ecfe l\u01b0ng h\u01a1n, code s\u01b0\u1edbng h\u01a1n. C\u00f2n th\u1ef1c t\u1ebf th\u00ec... N\u00f3 th\u00e0nh c\u00e1i c\u1edb ho\u00e0n h\u1ea3o \u0111\u1ec3... kh\u00f4ng ng\u1ed3i y\u00ean. L\u00fac code \u0111\u01b0\u1ee3c, t\u00f4i\u2026","rel":"","context":"Trong \"productivity hack\"","block_context":{"text":"productivity hack","link":"https:\/\/dangnh.cf\/vi\/tag\/productivity-hack\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/11\/image-1.png?fit=800%2C1200&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/11\/image-1.png?fit=800%2C1200&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/11\/image-1.png?fit=800%2C1200&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2025\/11\/image-1.png?fit=800%2C1200&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":66,"url":"https:\/\/dangnh.cf\/vi\/2017\/05\/19\/lam-toan-giai-tri-mot-ti-nhi\/","url_meta":{"origin":211,"position":5},"title":"L\u00e0m to\u00e1n gi\u1ea3i tr\u00ed m\u1ed9t t\u00ed nh\u1ec9?","author":"admin","date":"Th\u00e1ng 5 19, 2017","format":false,"excerpt":"Ok, ch\u00e0o t\u1ea5t c\u1ea3 anh em Ch\u1ea3 l\u00e0 cu\u1ed1i tu\u1ea7n, \u1edf nh\u00e0 r\u1ea3nh rang, tr\u1eddi th\u00ec se se l\u1ea1nh, m\u0169i h\u01a1i t\u1eafc, ch\u1ec9 mu\u1ed1n co ro qu\u1ea5n ch\u0103n \u00f4m laptop cho \u1ea5m. Lang thang thi c\u00e1i cu\u1ed9c thi l\u1eadp tr\u00ecnh c\u1ee7a b\u1ecdn Top Career g\u00ec \u0111\u00f3 :v v\u00f4 t\u00ecnh v\u1ea5p\u2026","rel":"","context":"Trong &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/dangnh.cf\/vi\/category\/web-development\/php\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2017\/05\/learning_math-e1459355151809.jpg?fit=800%2C513&ssl=1&resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/posts\/211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/comments?post=211"}],"version-history":[{"count":14,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/posts\/211\/revisions"}],"predecessor-version":[{"id":346,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/posts\/211\/revisions\/346"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/media\/349"}],"wp:attachment":[{"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/media?parent=211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/categories?post=211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/tags?post=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}