I’m trying to have it so, for every single Integer created, some text is outputted. For this, I’m looking to overload (or extend) the default Integer type.
I would like to have a built-in type (Integer, Array, String) to have a custom constructor like
public function __construct($data) { print $data; }
Is this possible? I can’t find it ever even attempted before online.
Edit:
I have tried this:
class Integer { /*...*/ }
And this:
class Integer extends Integer { /*...*/ }
Since PHP native scalar types are not objects, you cannot overload them.
You could write wrapper classes and use them like so:
But that’s probably much more work than makes sense.