PHP-Traits in Symfony: Add timestamps and more to tables magically

Say you want to add a logging preprocessor to some of your classes. Either all of these classes have to inherit some kind of logger-class, or you have to copy the logging-call multiple times. Not anymore! PHP 5.4.0 introduced Traits, a wonderful way to inject code into your classes without using inheritance.

A Trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way.

Some guys in the Symfony-community prepares some great traits:

  • Timestampable
  • Loggable
  • Translatable
  • Sortable
  • Tree

Go check them out:

https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/timestampable.md#traits

About 

Hi, I'm a Berlin-based developer and working on webstuff since 2000. My focus lies on PHP, TYPO3 and Symfony. 2009 I became a certified TYPO3-Integrator. I worked on projects for clients like Paypal, Union Investment, Commerzbank or Warsteiner.

Go check out my page http://www.christian-baer.com

Published by

Christian Baer

Hi, I'm a Berlin-based developer and working on webstuff since 2000. My focus lies on PHP, TYPO3 and Symfony. 2009 I became a certified TYPO3-Integrator. I worked on projects for clients like Paypal, Union Investment, Commerzbank or Warsteiner. Go check out my page http://www.christian-baer.com

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">