PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 5 ■ OBJECT TOOLS

Parameter #1 [ $firstName ]


Parameter #2 [ $mainName ]


Parameter #3 [ $price ]
Parameter #4 [ $playLength ]
}
}


Method [ public method getPlayLength ] {
@@ fullshop.php 63 - 65
}


Method [ <user, overwrites ShopProduct, prototype ShopProduct> public method
getSummaryLine ] {
@@ fullshop.php 67 - 71
}
}
}


As you can see, Reflection::export() provides remarkable access to information about a class.
Reflection::export() provides summary information about almost every aspect of CdProduct, including
the access control status of properties and methods, the arguments required by every method, and the
location of every method within the script document. Compare that with a more established debugging
function. The var_dump() function is a general-purpose tool for summarizing data. You must instantiate
an object before you can extract a summary, and even then, it provides nothing like the detail made
available by Reflection::export().


$cd = new CdProduct("cd1", "bob", "bobbleson", 4, 50 );
var_dump( $cd );


Here’s the output:

object(CdProduct)#1 (6) {
["playLength:private"]=>
int(50)
["title:private"]=>
string(3) "cd1"
["producerMainName:private"]=>
string(9) "bobbleson"
["producerFirstName:private"]=>
string(3) "bob"
["price:protected"]=>
int(4)
["discount:private"]=>
int(0)
}


var_dump() and its cousin print_r() are fantastically convenient tools for exposing the data in your
scripts. For classes and functions, the Reflection API takes things to a whole new level, though.

Free download pdf