0

I wanted to see what a function does, and I thought of looking at it just like how I find scripts in javascript

I'm looking for something that does the same as javascript's

function sampleFn() {
    return 'I am a sample'
}

console.log(sampleFn)
//function sampleFn() {
//    return 'I am a sample'
//}

I tried to do

print sampleFn;
echo sampleFn;
print_r(sampleFn);
//sampleFn

var_dump(sampleFn);
//string(11) "the_content"

I just want to know if there is a way to do it the same way javascript console.log() a function out

Eugene
  • 17
  • 5
  • Does this answer your question? [reconstruct/get code of php function](https://stackoverflow.com/questions/7026690/reconstruct-get-code-of-php-function) – Vlam Nov 07 '19 at 02:37
  • yes! that's what I'm looking for. it's a bit verbose than I was expecting though, but it works – Eugene Nov 07 '19 at 04:51

2 Answers2

0

To print the return value of a function, you need to call it like this:

echo sampleFn();

or

var_dump(sampleFn());

Please refer the PHP official documentation:

https://www.php.net/manual/en/functions.returning-values.php

Hashmat
  • 149
  • 1
  • 11
0

Sure you can ! And you were really close.

You can either use var_dump or echo, but you must add the parenthesis after you function name.

Example:

function sampleFn() {
    return "sample!";
}

var_dump(sampleFn());
Manu
  • 425
  • 4
  • 10