variable types

php.internals

Corne

19 years ago
Hi, I was trying to make PHP a bit more type-safe, but until now without success. I just want to do this for local testing, it's not important but it would be nice if it would work somehow.. Are there more people who tried this? What I want is the following: If you have a variable in you php code than it is typeless, for example you could do the following: $var = 'test'; $var = 1; It would be nice for me if I can make it possible that if you used a string in a variable, and after that use an integer (for example) that PHP then gives a warning. It would be even better if it is possible to force declaration of a variable with a type (something like int $varname), and than offcourse the error if you try to put something else inside.. This is the fist time I look in the source code of PHP, so I don't have a clue where to look for this or if it is even possible (without going through thousands of files).. Does anybody know if it is possible at all, and if so where to look for this? Thanks, Corne Ps. I'm sorry if my English isn't that great, it's not my native language.

Richard Lynch

19 years ago
Rather than re-designing the language, you might want to begin using: http://php.net/assert in your code... Just giving you an option you may have missed -- Not claiming you're "wrong" On Tue, December 5, 2006 2:45 pm, Corne wrote:
> Hi, > > I was trying to make PHP a bit more type-safe, but until now without > success. > I just want to do this for local testing, it's not important but it > would be > nice if it would work somehow.. > Are there more people who tried this? > What I want is the following: > If you have a variable in you php code than it is typeless, for > example you > could do the following: > $var = 'test'; > $var = 1; > It would be nice for me if I can make it possible that if you used a > string > in a variable, and after that use an integer (for example) that PHP > then > gives a warning. > It would be even better if it is possible to force declaration of a > variable > with a type (something like int $varname), and than offcourse the > error if > you try to put something else inside.. > > This is the fist time I look in the source code of PHP, so I don't > have a > clue where to look for this or if it is even possible (without going > through > thousands of files).. > Does anybody know if it is possible at all, and if so where to look > for > this? > > Thanks, > Corne > > Ps. I'm sorry if my English isn't that great, it's not my native > language. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?

DvDmanDT

19 years ago
First of all, this doesn't seem like a very good idea to do.. My suggestions below are for the first idea (throw a warning/error if a variable changes type). Second, I have never hacked the engine, and don't really have any ideas on how it accutually works, I'm just guessing here. Next, my first bet would be to hack the VM thingy, and find out how it does assignment. Then modify the code for assignment to perform a check on types in there. You would also need to hack the ze_fetch_arguments or whatever it's called (the one you use to find arguments passed to built-in functions) I believe, but again, just guessing here. BTW, there was a patch about type-hinting on this list fairly recently, you should check it out. It's one step in the "right" direction I think. When it comes to finding which files you'll need to hack.. .. grep, windows search, google code search, lxr.php.net, ...
-- // DvDmanDT mail: dvdmandt¤telia.com msn: dvdmandt¤hotmail.com ""Corne"" <corne-dickens@home.nl> skrev i meddelandet news:1C.0F.15259.4AAD5754@pb1.pair.com...

DvDmanDT

19 years ago
With ze_fetch_arguments I meant zend_parse_parameters (just a small spelling error.. ;-) )
-- // DvDmanDT mail: dvdmandt¤telia.com msn: dvdmandt¤hotmail.com ""Corne"" <corne-dickens@home.nl> skrev i meddelandet news:1C.0F.15259.4AAD5754@pb1.pair.com...