0

Is it possible to find the data about a built in method in PHP via code?

For example, we have array_key_exists() which is an internal method.

I want to find out the parameters in this function programatically. The reason is, there is an up coming interview, and I will have to write code on Notepad. There will not be any internet connection to see PHP documentation.

If I can get the information about built in methods via code, it will be really helpful.

Is it at all possible to print meta data of a function? I am not asking about user defined functions, but about PHP's built in functions.

Thanks a lot.

jcoder
  • 117
  • 1
  • 12
  • 1
    You can use this `$refFunc = new ReflectionFunction('preg_replace');` if Reflections is installed, but it sounds like cheating what you want to do ;-) http://php.net/manual/en/class.reflectionfunction.php – JustOnUnderMillions Jan 25 '17 at 14:04
  • `Notepad` Tip: If you have to use Notepad, i thing you dont can run scripts while interview ;) so no way to get information about functions.... – JustOnUnderMillions Jan 25 '17 at 14:06
  • Absolutely this is what I was searching for. Thanks a lot brother. Yeah, it is some kind of hacking or cheating :D ... It is a practical test. So they will ask me to write a program to do some x task. I will update you here later on. – jcoder Jan 26 '17 at 14:38

1 Answers1

0

You are looking for Reflection i think:

$refFunc = new ReflectionFunction('preg_replace');
foreach( $refFunc->getParameters() as $param ){
    print $param;
}

http://php.net/manual/de/class.reflectionfunction.php

enno.void
  • 6,242
  • 4
  • 25
  • 42
  • Thank you so much for this. It works. Is there any way to get the list of all PHP's built in methods or functions programatically? – jcoder Jan 26 '17 at 14:40
  • Is there a difference between function and method in PHP? I was a bit confused because I see people using both the terms often. – jcoder Jan 26 '17 at 14:41
  • Function to get all defined functions: get_defined_functions() For your second question look here: http://stackoverflow.com/questions/155609/difference-between-a-method-and-a-function (Please upvote if my answer was usefull) – enno.void Jan 26 '17 at 14:47
  • Thank you so much mr.void , excellent. I am so happy now, because if at all if I get stuck during the practical test, I can quickly use get_defined_functions() in combination with ReflectionFunction ... really cool thing. – jcoder Jan 28 '17 at 03:29