I have this framework project kind of on the backburner where I want to enforce the use of an Input
class to access all superglobals like $_POST
, $_GET
and $_SERVER
. A recent question here reminded me about it.
The class will do a little cleanup of the keys to make sure there's nothing malicious or unexpected, and provide a way to access items without the hassle of using isset()
each time. It may do other things depending on configuration, and will possibly clear the superglobals as well. I also don't like the fact that superglobals are not read-only, I want to enforce integrity in the values. I want this class to be used exclusively, and want to warn developers when it is not used.
My question is this, and I fear the answer is "No":
Is it possible to to trigger an error when one of the superglobals is accessed? For example:
$myvar = $_POST['key'];
// Prints "Error: POST cannot be accessed directly, use the Input class instead"
Or when writing to superglobals?:
$_POST['key'] = 'myvalue';
// Prints "Error: POST data cannot be modified"
$_POST = "Hello World";
(assigning specific keys does trigger the error) - any idea? – Champollion