1

I am trying to figure out a big PHP Library and it isn't that well documented. I would like to know if there is a way to print out everything about the class. For example I am using the get_class_methods() function to print out the methods of that class and it prints out an area of just that class. I would like to see all the methods within the objects within that class as well. It would be nice to see the variables and everything else. This way I can print out everything and then use the browser's search to find stuff that I need. Is this possible, or is there a method out there that already does this? I'm not that well versed in PHP so if you can give me a function that would be awesome.

1
  • Get_class_methods does return the methods from a class, but why don't you open the library and just read the code instead? Commented Dec 17, 2015 at 22:11

2 Answers 2

3

PHP has a built in library called Reflection that allows you to analyze classes and objects in intricate detail.

You can get all the methods in a class like so:

<?php 
$class = new ReflectionClass('Apple');
$methods = $class->getMethods();
var_dump($methods);

For class properties (member variables):

<?php 
$class = new ReflectionClass('Apple');
$properties = $class->getProperties();
var_dump($properties);
Sign up to request clarification or add additional context in comments.

6 Comments

Is there a method call that would do that for me, my class is called $shape
Well, $shape is a variable object name, not a class.
Yeah that's the object that I would like to see everything in.
If you already know the name of the class for that object, you can just use a string literal "classNameHere", or you can use get_called_class($shape), and pass it to the reflection class.
I used get_class($shape) and it appeared to work. Thank you!
|
-1

A good IDE will help you navigate through the code, start debugging sessions and inspect properties values in execution time.

I felt in love with PHPStorm some years ago, and still today it's my favourite IDE. It even has a Vim plugin which emulates vim =)

There is a Structure view on that IDE, which shows the, well :), code structure of a file. This means every property and method of the opened class file. There is a Project view which is like a directory browser too.

Second recommendation will be to install ack (http://www.beyondgrep.com). PHPStorm has a really efficient searching mechanism, but sometimes you just want to search the entire subdirectories of a project for a regular expression. It's a neat tool also.

My two cents. :)

3 Comments

Do you know of a free IDE that does that ?
I used to code with vim and its plugins. Ack is free and has vim integration. But you should seriously consider jetbrains' IDE. It had a plan in which you download builds every month and use (helping to test therefore) for a month, freely.
@kingcobra1986 Sorry for the late comment, but nowadays I don't use phpstorm anymore because I found out vdebug. I even forked to fix a bug in it, it's a vim interface for xdebug: github.com/niloct/vdebug (so it's everything free).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.