Search code examples
phpcustom-data-type

How to make custom datatypes in php?


I know in other languages how to make a new custom datatype, but how do I do this in PHP? Sometimes I need something that doesn't fit in the categories of a String, Integer, Float, Bool, Array, Object, Null, or Resource (often with a very different set of standard interactions and operators). How do I do this?


Solution

  • There is no way to add custom datatypes to PHP, I could not find any way or documentation saying you could, but I think you can always modify the PHP Core in order to achieve that (Which I would not recommend to do if you dont know what you are doing).

    My suggestion is to create classes, that way you can typehint a variable by its classname.