title: Structuring Decorators in PHP
body: <p>I'm sort of a novice developer trying to expand my toolbox and learn some more tricks. I recently came across a pattern in Python called "decoration" and I was wondering if/how I could implement this in PHP as I have an existing PHP code base.</p>
  
  <p>Here is a short example of what I mean:</p>
  
  <pre><code>import time
  
  def log_calls(func):
      def wrapper(*args, **kwargs):
          now = time.time()
          print("Calling {0} with {1} and {2}".format(
              func.__name__,
              args,
              kwargs
          ))
          return_value = func(*args, **kwargs)
          print("Executed {0} in {1}ms".format(
              func.__name__,
              time.time() - now
          ))
          return return_value
      return wrapper
  
  @log_calls
  def test1(a,b,c):
      print("\ttest1 called")
  
  @log_calls
  def test2(a,b):
      print("\ttest2 called")
  
  @log_calls
  def test3(a,b):
      print("\ttest3 called")
      time.sleep(1)
  
  test1(1,2,3)
  test2(4,b=5)
  test3(6,7)
  </code></pre>
  
  <p>It doesn't necessarily have to be that syntactically pretty; I understand that all languages have their nuances and I know PHP does not support that syntax. But I still want to be able to achieve the same effect while rewriting as little code as possible.</p>