Jump to content

absolute newb need answer for settype(), gettype() problem


iansane

Recommended Posts

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

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) :-)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.