Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 363
lilHar Avatar asked Nov 01 '25 02:11

lilHar


1 Answers

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.

like image 133
taxicala Avatar answered Nov 03 '25 16:11

taxicala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!