0

Let's say you have a file containing a PHP array with a direct return, like:

return [
    'key1' => 'value1',
    'key2' => 'value2',
    'key3' => 'value3',
];

For reference. Name this data.php And you require (or include) this file in your code.

public function getDataWithName(string $name) {
    return require $name . '.php';
}

Now what happens when you execute -> getDataWithName('data') multiple times within the project?

Given that the file can be much much larger. And doing 100+ calls to this function within the script execution, how does this translate to memory? Is the file being read X amount of times, or only once whereas the second or third times it is loaded by reference?

Jordi Kroon
  • 2,538
  • 3
  • 30
  • 55

0 Answers0