• 11

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

Reflection is definitely here to stay. You may use it, but keep in mind it is said to be slow and overkill for simple UseCases. Using one of the functions in the Classes/Objects function package is often the faster alternative.

A UseCase where Reflection comes in handy is when parsing for annotations in the DocBlock of a class. For instance, PHPUnit uses the annotations @test to tell the PHPUnit TestRunner that it should consider a method a test. The @covers annotation will help it collect Code Coverage data. The FLOW3 framework makes use of Annotations for their AOP framework.

Unfortunately, some of the newer additions to PHP > 5.3, are not documented yet that much. Just look at the SPL. Same thing. That doesn't mean you cannot use it though. The Reflection API is very expressive and easy to figure out from the method names. And Google often has blog posts about how to use certain extensions. For the Reflection API, check out:

and for SPL

Something cool I just discovered recently. As of 5.1.2, you can invoke the Reflection API from the command line too:

$php --rf strtotime
Function [ <internal:date> function strtotime ] {

  - Parameters [2] {
    Parameter #0 [ <required> $time ]
    Parameter #1 [ <optional> $now ]
  • 16
Reply Report
    • I can and I did, my C skills are just a little higher than monkey's and I was wondering if you have an answer already. It would be interesting to know without doing the hard work – not the usual approach, promise :)
      • 2
    • @IanBytchek actually, a monkey would beat me at C, so I am afraid I don't have a answer. But you can join the PHP room where lots of knowledgeable people are around who might be able to answer your question.
    • Is there any information on how it actually works behind the scenes? I know it's not super fast, which is understandable. But is it because it parses the code all the time or does it use something smarter, like maybe when the class is loaded into memory it gets digested into smaller chunks and this information is used to "reflect" the actual class?

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions