Home > Blockchain >  How do I read the source code without access to file
How do I read the source code without access to file

Time:02-02

i want to ask if it is possible to read the php sourcecode (without access to file.inc) of an included file and/or single function? example

file.inc

function thatIsMyFunction( $a ){
  $x = $a * 3 / ($a   7);
  return $x;
} 

index.php

include_once("../path/file.inc");
// something like that 
var_dump(thatIsMyFunction());
// to see: 
//  $x = $a * 3 / ($a   7);
//  return $x;

CodePudding user response:

You can technically see the function content using Reflection, but you must include the file.

function thatIsMyFunction($a) {
    $x = $a * 3 / ($a   7);
    return $x;
}
 
function function_dump($function) {
    try {
        $func = new ReflectionFunction($function);
    } catch (ReflectionException $e) {
        echo $e->getMessage();
        return;
    }
 
    $start = $func->getStartLine() - 1;

    $end =  $func->getEndLine() - 1;
 
    $filename = $func->getFileName();
 
    echo implode("", array_slice(file($filename),$start, $end - $start   1));
}

 
function_dump('thatIsMyFunction');

// will dump
/*
function thatIsMyFunction($a) {
    $x = $a * 3 / ($a   7);
    return $x;
};
*/

  •  Tags:  
  • Related