0

Hi I need to get the result (variable) from other PHP file. However, the included file will call some library and codes which conflicted to my codes.

For example

new.php


function getOld(){
    ob_start();
    include( __DIR__.'/old.php' );
    return ob_get_clean();
}
$a = getOld();
var_dump($a); // able to get the result (echoed json) from old.php

define("version", "1.0"); // Warning, cannot re-defined
include "new version library" // The old version library is inited

old.php

define("version", "0.1");
include "old version library";

// Many logics here...


echo json_encode(array("id"=>........));

I know that I can use Ajax to call the file, however the server set to cannot direct call library files and many files need to changed.

Is there any faster way to get other php files result without including the codes (like a sandbox)

saakrubber
  • 79
  • 7
  • 1
    What about trying to initiate a curl request to retrieve a result of a function in the file to capture result of desired script without inclusion. This post might relate to your need. https://stackoverflow.com/questions/6560512/send-http-request-with-curl-to-local-file, alternatively, as an afterthought, it might be necessary to encapsulate the file contents within a class function or in a namespace or class to prevent conflict. – Vahe Aug 09 '21 at 03:06
  • 1
    try by initiating curl request to call the particular file and method. It would be more better. – PHP Geek Aug 09 '21 at 06:49

0 Answers0