Possible value is "unicode" starting PHP6.
![]() |
|
||||||||||
|
settypeDescriptionbool settype ( mixed &var, string type )
Set the type of variable
Possibles values of
Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.
See also gettype(), type-casting and type-juggling. settype
sneskid at hotmail dot com
05-Mar-2007 02:57
In response to the guy who was having troubles with leading zeros and wrote the convertToInt function.
ludvig dot ericson gmail.dot com
09-Apr-2006 08:36
To matt:
matt at mattsoft dot net
06-Dec-2005 09:49
using (int) insted of the settype function works out much better for me. I have always used it. I personally don't see where settype would ever come in handy.
Michael Benedict
29-Oct-2005 10:55
note that settype() will initialize an undefined variable. Therefore, if you want to preserve type and value, you should wrap the settype() call in a call to isset().
25-Oct-2005 06:30
James Reiher (IL) writes:
25-Sep-2005 01:24
In response to the comment by Neoja regarding validating every variable in the URL using settype -- that is wrong.
nospamplease at veganismus dot ch
22-Jul-2005 07:38
you must note that this function will not set the type permanently! the next time you set the value of that variable php will change its type as well.
16-May-2005 12:22
I needed to pull a zerofilled integer out of a MySQL table and increment it by a certain amount. Unfortunately, PHP treated this integer as if it were a string when I tried to add an amount to it. For instance:
reinier_deblois at hotmail dot com
13-Mar-2005 09:18
Instead of settype you could use:
James Reiher (IL)
22-Feb-2005 09:50
I had a problem with PHP destroying the value of my integer with leading zeros as follows:
memandeemail at gmail dot com
09-Dec-2004 05:17
/**
23-Nov-2004 01:34
in PHP3 converting a string to any number results in the value becoming 0. To check if a string represents a number try this:
sdibb at myway dot com
06-Sep-2003 10:03
Using settype is not the best way to convert a string into an integer, since it will strip the string wherever the first non-numeric character begins. The function intval($string) does the same thing.
djworld at php dot net
17-Jul-2002 06:02
Usually it won't be necessary to use this function, but some times you need to be sure the variables are of some kind. For example, if you send a number to a database query from a variable passed by GET or POST, you may get sure it's a number by doing SetType ($var, 'integer'); so you can avoid security holes if it isn't a number and you don't need to addslashes() it, or for example, if you need to be sure that a number won't have any decimals after rounding it, you may do the same and as it will be an integer, it won't contain decimals.
r dot schechtel at web dot de
06-Aug-2001 02:59
To: neoja@hotmail.com
neoja at hotmail dot com
17-Feb-2001 06:42
It is always good to validate all the variables that are given in the url and would cause an error if they are of wrong type. For example, if your page is products.php?id=123 then run settype($id, "integer") in the script, before getting the product info from the database. If the user enters a non-numeric value in the url -- either pasting it wrong or intentionally :) -- the $id will be set to zero and database query will have no errors.
slushpupie at hotmail dot com
22-Jul-2000 09:07
in PHP3 converting a string to any number results in the value becoming 0. To check if a string represents a number try this:
support at mastebyte dot de
11-Jul-2000 12:39
Note that settype($string, "integer") will set $string to 0 if $string contains any lettery, but the function call will be TRUE
ns at canada dot com
05-May-2000 04:38
This settype() behaviour seems consistent to me. Quoting two sections from the manual:
tboothby at felfel dot com
10-Apr-2000 07:33
settype() for some reason increases the initial internal counter for the index of an array if you use<br>
jeffg at NOcounterintuitive dot orgSPAM
27-Oct-1999 02:46
It's worth noting that one can neither <I>settype()</i> nor type-cast a variable as a long. The workaround for this seems to be to use <I>pack()</i>.
|