# variable types

- Thread: https://externals.io/message/26806
- Original archive: https://news-web.php.net/php.internals/26806
- Started by Corne on 2006-12-05T20:45:21+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #26806 — Corne — 2006-12-05T20:45:21+00:00

URL: https://externals.io/message/26806#26806

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.

---

## #26877 — Richard Lynch — 2006-12-09T20:05:42+00:00

URL: https://externals.io/message/26806#26877 · In reply to: #26806

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"


> 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.
>
> --
> 
> 
>
>


-- 
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?
