|
Posted by Erwin Moller on 04/12/06 10:55
Tijs Verwest wrote:
> It's a newbie question...
>
> Is it possible to type variable in PHP inspite this is a loose type
> language. Or would that be required in some cases?
Hi,
PHP has the concept of types, however:
From manual:
-----------------
The type of a variable is usually not set by the programmer; rather, it is
decided at runtime by PHP depending on the context in which that variable
is used.
-----------------
Read more here:
http://nl2.php.net/manual/en/language.types.php
Also be sure to follow the link to 'Type Juggling'.
So, unlike strongtyped languages, in PHP you let the interpretation of the
type of a variable to the language itself.
In case of doubt you can ALWAYS cast to the type you want/demand.
for example:
$myInt = (int)$unclearValue;
You can also test for types, but that is all in the documentation.
In my experience, you do need the casting sometimes, but once you get
familiar with PHP it is easy to spot where.
If in doubt: just cast.
Good luck,
Erwin Moller
Navigation:
[Reply to this message]
|