Morning! Suppose I wanted to be able to rewrite 'require' to do some pre/post processing to the required files, so that the below would be true:
<?php
registerMagicalMysteryRequireOverwrite();
$xml = require './xml.xml';
$dir = require './';
$db = require './db.sqlite';
$isXML = $xml instanceof SimpleXML;
$isDir = $dir instanceof RecursiveDirectoryIterator;
$isDB = $db instanceof SQLite3;
$magicWorked = $isXML && $isDir && $isDB;
This could, among other things, simplify my code (like above), allow me to better sandbox other people's code (by only injecting the scope I choose into the require), let me inject random other language's code as long as a parser for them exists, etc. It would potentially be super useful. If it was a thing that existed, tho.
Can I do this? How can I do this? Thanks!