do you personally use reflection class?  Is this something I need to learn?

rgb192 used Ask the Experts™
I am learning about reflection class because
reflection class is in 4th edition of matt zandstra 'objects patterns practice'

I also read (not understood) 3rd edition years ago

I have not read first, second

my question:
Do you use reflection class?
After reading expert comment who says 'rarely', I think maybe I am reading about reflection class because it could have been in a first edition of a book and updated for a fourth edition
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
If you are learning PHP and OO at the same time I would leave this topic for later.

It is used on large projects but I don't think you are going to need it at this level. First get the basics of PHP and OO right and once you have those firmly in place then move onto topics like Reflection.

If you are going to be desiging an OO hierarchy then this is something you should know about - personally I think if you are just learning the ropes with PHP and OO - it can confuse more than it can enlight.
Most Valuable Expert 2011
Top Expert 2016
You may be able to answer your own question by reading this:

Why would you need that?  Why not just go straight to the man page and read this?

Or install this little script and run it.  It shows different ways of looking at the same information that is apparent in the source code.  If you know how to read the source code, this is "nice to have" but it does not add much value to your understanding.

<?php // demp/reflection.php

// SEE

function title($title, $name)
    return sprintf("%s. %s" . PHP_EOL, $title, $name);
echo ReflectionFunction::export('title',true);

Open in new window

That's why I rarely find any use for Reflectors.
hello , I have NEVER found ANY useful way to do the reflection in PHP, and I tried by using it! ! The reflection CODE does work, and it does get info about a class, but the info is NOT HELPFUL to me, as it's in the Class Definition code already!

I really agree with "julianH" saying - "If you are learning OO , I would leave this topic for later."

I would recomend that for a Beginner in PHP object-class code, that they
learn about -
1. Abstract Class , abstraction in code work is VERY COMPLICATED and no beginner should be introduced to it.

2. NameSpaces , This ONLY has any use for LARGE and complex Class setups, that a beginner will take many years to ever code in, or probably never code in a Large One.

3. Reflection Info, This is a class code that is difficult to understand how and why to use it. And will only confuse a beginner.

4. Interface , the Interface Class setup, is (in my opinion) NOT to declare your own Interface, , the PHP Interface is there so you can use the built in PHP "Predefined Interfaces" - "Traversable", " Iterator", "IteratorAggregate", "ArrayAccess", "Serializable", "Closure", "Generator" and the SPL Interfaces.
For example make your Class Objects do special work in a foreach( ) loop, by declaring -
        class dataCheck implements Iterator {

== = = = = = = =
the above is just some of my suggestions for you as a beginner, you have enough to learn about the core - fundamental "Important" OO code work, and not be confused by areas of Class code work that you do not need until much later.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.


Slick812 I asked this question because of one of your comments

You wrote alot of

but what should I learn as a beginner to oop?

And Julian
what are
First get the basics of PHP and OO right



I realized that my original question was answered.
I think Ray's answer of a code sample about Reflection was good but following advice of all three experts; I ran once and did not spend hours learning.

My followup question is:
AHH, rgb192, a good question! You have asked several questions here in EE about PHP Object tutorials, and as you say this question is about the "4th edition" , and you say - "I also read (not understood) 3rd edition years ago"
You seem to think that Object Oriented programming code is a very different thing than the normal PHP code without objects. The way you use Objects in code with a ->  is different that the other older way, and putting code inside of a Class is also different, but for me the WORK that has to be done for a web page output, is the SAME code work, like to connect to database -
try {$dbo = new PDO("mysql:host=host;dbname=db1", "name", "password");

you have to use that same line of code whether you use OO or normal PHP code, and you also MUST use the code -
$stmt = $dbo->prepare('INSERT INTO guest1 (name, date, email) . . . .

whether you use OO or normal PHP code, , to place the data needed for your site to work,  into the DB table.
You have seemed to miss the understanding that  the Class code writing is suppose to be a GOOD way to get neccessary work done (database access, sort arrays, do product displays in HTML table rows, re-size Images) for one or many PHP pages in a functional web site. You need to know about -
1. Basic Class - properties, declare a method, what $this is a reference to, the __construct( ) , using the "new" to produce an object. , what static can be used for.

2. Try and SEE HOW doing a Class can HELP you do better code, because you REDUCE the amount of code and WORK a developer does, saves them TIME and HEADACHES.

here is some code that I actually used-
<?php include 'p4pLook.php';
$p4obj = new p4pLook('hilight',216,'kowork');?><!doctype html>
<html lang="en"><head><title>JQuery Ajax for PHP</title><link rel="stylesheet" type="text/css" href="p4p.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<script src="p4p.js"></script>
<?php $p4obj->doHead('Products on Sale',3); ?>
<div id="mid"><center>
<?php $p4obj->doBlu('intro531.txt',true); 
$p4obj->doBar();$p4obj->doOrngCor('Specials!', 'ox1', 'specials1.txt');
$p4obj->doBar();$p4obj->doProduct('ID-sale448', 'ox2',580);
<?php $p4obj->doFoot('obsto42.txt'); ?>
<script>/* <![CDATA[ */
var mHgt=menu1.offsetHeight-12;
var aNum = menu1.getElementsByTagName("a");
for(var i=0;i< aNum.length;i++) {aNum[i].onclick=nomenu;}
/* ]]> */</script>

Open in new window

I have used my p4pLook.php, which has a CLASS in it, then I get an object with -
$p4obj = new p4pLook(

and produce some complex and lengthy page code writes with methods-
$p4obj->doBlu( )
using CONDITIONALS  'hilight',216,'kowork'   from the object creation
new p4pLook('hilight',216,'kowork');

by using this
$p4obj = new p4pLook( )
in several different pages, I do NOT have to re-write 40 to 120 lines of PHP code and just have one line -
$p4obj->doOrngCor('Specials!', 'ox1', 'specials1.txt');

this saves me TIME and effort! BUT IF, I did NOT use a CLASS and object, I would still have to write the same PHP work code (mysql access, image retrieval and check, price check, inventory check) that I do in a Class, and the Class code Helps me do less work!


Hi Slick812,
I opened a new question to ask a question about your comment.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial