{"id":448,"date":"2014-09-28T11:33:39","date_gmt":"2014-09-28T19:33:39","guid":{"rendered":"http:\/\/www.tech.dimprash.com\/?p=448"},"modified":"2014-09-28T11:33:39","modified_gmt":"2014-09-28T19:33:39","slug":"traits","status":"publish","type":"post","link":"http:\/\/www.tech.dimprash.com\/?p=448","title":{"rendered":"Traits"},"content":{"rendered":"<p>As of PHP 5.4.0, PHP implements a method of code reuse called Traits.<\/p>\n<p>Traits are 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. The semantics of the combination of Traits and classes is defined in a way which reduces complexity, and avoids the typical problems associated with multiple inheritance and Mixins.<\/p>\n<p>A Trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate a Trait on its own.<\/p>\n<p><code>trait ezcReflectionReturnInfo {<br \/>\n    function getReturnType() { \/*1*\/ }<br \/>\n    function getReturnDescription() { \/*2*\/ }<br \/>\n}<\/p>\n<p>class ezcReflectionMethod extends ReflectionMethod {<br \/>\n    use ezcReflectionReturnInfo;<br \/>\n    \/* ... *\/<br \/>\n}<\/p>\n<p>class ezcReflectionFunction extends ReflectionFunction {<br \/>\n    use ezcReflectionReturnInfo;<br \/>\n    \/* ... *\/<br \/>\n}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As of PHP 5.4.0, PHP implements a method of code reuse called Traits. Traits are 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 &hellip; <a href=\"http:\/\/www.tech.dimprash.com\/?p=448\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Traits<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-448","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=448"}],"version-history":[{"count":1,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/448\/revisions"}],"predecessor-version":[{"id":449,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=\/wp\/v2\/posts\/448\/revisions\/449"}],"wp:attachment":[{"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=448"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tech.dimprash.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}