{"id":211,"date":"2018-06-01T14:45:31","date_gmt":"2018-06-01T06:45:31","guid":{"rendered":"https:\/\/dangnhsite.wordpress.com\/?p=211"},"modified":"2026-08-18T15:35:04","modified_gmt":"2026-08-18T07:35:04","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>PHP l\u00e0 ng\u00f4n ng\u1eef \u0111\u01a1n k\u1ebf th\u1eeba, v\u00e0 c\u00e2y k\u1ebf th\u1eeba d\u00e0i lu\u00f4n l\u00e0 c\u01a1n \u00e1c m\u1ed9ng. Trait sinh ra \u0111\u1ec3 gi\u1ea3i quy\u1ebft chuy\u1ec7n \u0111\u00f3 \u2014 nh\u01b0ng khi n\u00e0o n\u00ean d\u00f9ng, v\u00e0 khi n\u00e0o n\u00ean tr\u00e1nh?<\/p>","protected":false},"author":1,"featured_media":349,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_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},"jetpack_post_was_ever_published":false},"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 v28.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Trait - Mixin in PHP?  - Mark Nguyen<\/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 Nguyen\" \/>\n<meta property=\"og:description\" content=\"PHP l\u00e0 ng\u00f4n ng\u1eef \u0111\u01a1n k\u1ebf th\u1eeba, v\u00e0 c\u00e2y k\u1ebf th\u1eeba d\u00e0i lu\u00f4n l\u00e0 c\u01a1n \u00e1c m\u1ed9ng. Trait sinh ra \u0111\u1ec3 gi\u1ea3i quy\u1ebft chuy\u1ec7n \u0111\u00f3 \u2014 nh\u01b0ng khi n\u00e0o n\u00ean d\u00f9ng, v\u00e0 khi n\u00e0o n\u00ean tr\u00e1nh?\" \/>\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 Nguyen\" \/>\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=\"2026-08-18T07:35:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1\" \/>\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\\\/vi\\\/#\\\/schema\\\/person\\\/8f3b9db3b250186af217fbeec88eda9c\"},\"headline\":\"Trait &#8211; Mixin in PHP?\",\"datePublished\":\"2018-06-01T06:45:31+00:00\",\"dateModified\":\"2026-08-18T07:35:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/2018\\\/06\\\/01\\\/trait-mixin-in-php\\\/\"},\"wordCount\":632,\"commentCount\":1,\"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 Nguyen\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/vi\\\/#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\":\"2026-08-18T07:35:04+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/dangnh.cf\\\/vi\\\/#\\\/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\\\/vi\\\/#website\",\"url\":\"https:\\\/\\\/dangnh.cf\\\/vi\\\/\",\"name\":\"Mark Nguyen\",\"description\":\"I build the e-commerce backends customers never see \u2014 payments, integrations, and AI features that actually ship.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/dangnh.cf\\\/vi\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"vi\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/dangnh.cf\\\/vi\\\/#\\\/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 Nguyen","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 Nguyen","og_description":"PHP l\u00e0 ng\u00f4n ng\u1eef \u0111\u01a1n k\u1ebf th\u1eeba, v\u00e0 c\u00e2y k\u1ebf th\u1eeba d\u00e0i lu\u00f4n l\u00e0 c\u01a1n \u00e1c m\u1ed9ng. Trait sinh ra \u0111\u1ec3 gi\u1ea3i quy\u1ebft chuy\u1ec7n \u0111\u00f3 \u2014 nh\u01b0ng khi n\u00e0o n\u00ean d\u00f9ng, v\u00e0 khi n\u00e0o n\u00ean tr\u00e1nh?","og_url":"https:\/\/dangnh.cf\/vi\/2018\/06\/01\/trait-mixin-in-php\/","og_site_name":"Mark Nguyen","article_publisher":"https:\/\/www.facebook.com\/dangtute","article_published_time":"2018-06-01T06:45:31+00:00","article_modified_time":"2026-08-18T07:35:04+00:00","og_image":[{"width":960,"height":540,"url":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1","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\/vi\/#\/schema\/person\/8f3b9db3b250186af217fbeec88eda9c"},"headline":"Trait &#8211; Mixin in PHP?","datePublished":"2018-06-01T06:45:31+00:00","dateModified":"2026-08-18T07:35:04+00:00","mainEntityOfPage":{"@id":"https:\/\/dangnh.cf\/2018\/06\/01\/trait-mixin-in-php\/"},"wordCount":632,"commentCount":1,"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 Nguyen","isPartOf":{"@id":"https:\/\/dangnh.cf\/vi\/#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":"2026-08-18T07:35:04+00:00","author":{"@id":"https:\/\/dangnh.cf\/vi\/#\/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\/vi\/#website","url":"https:\/\/dangnh.cf\/vi\/","name":"Mark Nguyen","description":"I build the e-commerce backends customers never see \u2014 payments, integrations, and AI features that actually ship.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dangnh.cf\/vi\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Person","@id":"https:\/\/dangnh.cf\/vi\/#\/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_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":"stdClass xu\u1ea5t hi\u1ec7n kh\u1eafp n\u01a1i trong core c\u1ee7a Laravel v\u00e0 Yii. N\u00f3 l\u00e0 c\u00e1i g\u00ec, t\u1ea1i sao dev kh\u1ee7ng th\u00edch d\u00f9ng, v\u00e0 l\u00e0m sao \u0111\u1ec3 c\u00f3 dynamic properties trong PHP?","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":"Service Container l\u00e0 tr\u00e1i tim trong ki\u1ebfn tr\u00fac Laravel. Khi b\u00e0i to\u00e1n l\u1edbn d\u1ea7n v\u00e0 b\u1ea1n ph\u1ea3i qu\u1ea3n l\u00fd nhi\u1ec1u service c\u00f9ng dependency, \u0111\u00e2y l\u00e0 th\u1ee9 b\u1eaft bu\u1ed9c ph\u1ea3i hi\u1ec3u.","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":406,"url":"https:\/\/dangnh.cf\/vi\/2025\/05\/19\/trait-mixin-in-php-part-2\/","url_meta":{"origin":211,"position":2},"title":"Trait \u2013 Mixin in PHP? &#8211; PART 2","author":"admin","date":"Th\u00e1ng 5 19, 2025","format":false,"excerpt":"Ph\u1ea7n 2 c\u1ee7a series Trait trong PHP: x\u1eed l\u00fd xung \u0111\u1ed9t v\u1edbi insteadof v\u00e0 as, abstract method, static property, trait l\u1ed3ng trait, c\u00f9ng c\u00e1c best practice khi d\u00f9ng trait th\u1eadt.","rel":"","context":"Trong &quot;PHP&quot;","block_context":{"text":"PHP","link":"https:\/\/dangnh.cf\/vi\/category\/web-development\/php\/"},"img":{"alt_text":"Trait in PHP","src":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/dangnh.cf\/wp-content\/uploads\/2018\/06\/retro-background-3101430_960_720.jpg?fit=960%2C540&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":3},"title":"H\u01b0\u1edbng D\u1eabn Setup AI Blog to Podcast Agent","author":"admin","date":"Th\u00e1ng 5 19, 2025","format":false,"excerpt":"H\u01b0\u1edbng d\u1eabn ch\u1ea1y th\u1eed AI Blog to Podcast Agent t\u1eeb repo Awesome LLM Apps ngay tr\u00ean m\u00e1y Mac \u2014 bi\u1ebfn m\u1ed9t b\u00e0i blog th\u00e0nh t\u1eadp podcast ho\u00e0n ch\u1ec9nh.","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":4},"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 (Retrieval-Augmented Generation) l\u00e0 c\u00e1ch gi\u00fap AI b\u1edbt \"n\u00f3i x\u1ea1o\" b\u1eb1ng vi\u1ec7c tra t\u00e0i li\u1ec7u tr\u01b0\u1edbc khi tr\u1ea3 l\u1eddi. Gi\u1ea3i th\u00edch d\u1ec5 hi\u1ec3u, k\u00e8m v\u00ed d\u1ee5 th\u1ef1c t\u1ebf v\u00e0 c\u00e1c b\u01b0\u1edbc tri\u1ec3n khai.","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":5},"title":"Standing desk &#8211; V\u1eadt trang tr\u00ed \u0111\u1eaft ti\u1ec1n hay m\u1eb9o hack productivity?","author":"admin","date":"Th\u00e1ng 11 5, 2025","format":false,"excerpt":"Mua b\u00e0n \u0111\u1ee9ng, t\u00f4i t\u01b0\u1edfng m\u00ecnh s\u1ebd th\u00e0nh si\u00eau nh\u00e2n n\u0103ng su\u1ea5t. Th\u1ef1c t\u1ebf th\u00ec n\u00f3 th\u00e0nh c\u00e1i c\u1edb ho\u00e0n h\u1ea3o \u0111\u1ec3\u2026 kh\u00f4ng ng\u1ed3i y\u00ean. V\u00e0i ghi ch\u00e9p th\u1eadt l\u00f2ng c\u1ee7a m\u1ed9t th\u1eb1ng dev.","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":[]}],"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","_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":15,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/posts\/211\/revisions"}],"predecessor-version":[{"id":524,"href":"https:\/\/dangnh.cf\/vi\/wp-json\/wp\/v2\/posts\/211\/revisions\/524"}],"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}]}}