iansane Posted August 9, 2008 Share Posted August 9, 2008 Hi, I'm just starting out and learning about settyp() and gettyp(). I used the following code and the resulting data type is wrong. $my_var = 1995; //$my-var is a numeric value echo "The varaivle is now a ". gettype($my_var) . "<br>"; $my_var = settype($my_var, "string"); //$my_var is now a string echo "The variable is now a " . gettype($my_var); the result is that the variable is now "boolean" and the data contained in it from "echo $myvar" is just "1". In the book it says something about "not the string you were hoping for" but I don't see any explaination of why and how to resolve the problem. Can someone please explain this to me? Sorry to have to post such a small thing but it's hard to learn when right off the bat things aren't working right. Thanks Link to comment https://forums.phpfreaks.com/topic/118930-absolute-newb-need-answer-for-settype-gettype-problem/ Share on other sites More sharing options...
iansane Posted August 9, 2008 Author Share Posted August 9, 2008 OK, I figured this one out. After looking at it again I thought line 3 doesn't look right. It should be settype = ($my_var, "string") NOT as the book says, $my_var = settype ($my_var, "string") I still don't know why this caused it to change the type to boolean. I guess I'll need to spend more time modifying code to figure it out when I have little problems like this. I don't know if the book was trying to make a point or just had a typo. Who would expect the code in a published book to be correct or for there to be complete explanations in a book titled "Beginning PHP5"? (sarcasm) :-) Link to comment https://forums.phpfreaks.com/topic/118930-absolute-newb-need-answer-for-settype-gettype-problem/#findComment-612421 Share on other sites More sharing options...
iansane Posted August 9, 2008 Author Share Posted August 9, 2008 my mistake. It should be settype($my_var, "string"); time ran out before I could edit the last post Link to comment https://forums.phpfreaks.com/topic/118930-absolute-newb-need-answer-for-settype-gettype-problem/#findComment-612432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.