Jump to content

Recommended Posts

hello all,

 

I am extremely new to php and so far I like it. Basically, I am in a section of my book where it teaches how to change the type of a variable using settype() function.

settype($variable_to_change, 'new_variable_type');

 

here is my code

<?php
$undecided = 3.14;
echo "Is " .$undecided. " a double? " .is_double($undecided). "<br />" // double
settype ($undecided, 'string');
echo "Is " .$undecided. " a string? " .is_string($undecided). "<br />" // string
settype ($undecided, 'integer');
echo "is " .$undecided. " an integer? " .is_int($undecided). "<br />" // integer
settype ($undecided, 'double');
echo "is " .$undecided. " a double? " .is_double($undecided). "<br />"; // double
settype ($undecided, 'bool');
echo "is " .$undecided. " a boolean? " .is_bool($undecided). "<br />"; // boolean
?>

 

In my browser, it says the following error:

Parse error: parse error, expecting `','' or `';'' in C:\wamp\www\sams\5\changing_variables.php on line 4

 

I followed the book.. can you please point out what exactly is wrong here?

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/147695-solved-newbie-cant-get-settype-to-work/
Share on other sites

You forgot to include ";" on line four and line six and eight.

<?php
$undecided = 3.14;
echo "Is " .$undecided. " a double? " .is_double($undecided). "<br />"; // double
settype ($undecided, 'string');
echo "Is " .$undecided. " a string? " .is_string($undecided). "<br />"; // string
settype ($undecided, 'integer');
echo "is " .$undecided. " an integer? " .is_int($undecided). "<br />"; // integer
settype ($undecided, 'double');
echo "is " .$undecided. " a double? " .is_double($undecided). "<br />"; // double
settype ($undecided, 'bool');
echo "is " .$undecided. " a boolean? " .is_bool($undecided). "<br />"; // boolean
?>

You forgot to include ";" on line four and line six.

<?php
$undecided = 3.14;
echo "Is " .$undecided. " a double? " .is_double($undecided). "<br />" // double
settype ($undecided, 'string');
echo "Is " .$undecided. " a string? " .is_string($undecided). "<br />"; // string
settype ($undecided, 'integer');
echo "is " .$undecided. " an integer? " .is_int($undecided). "<br />"; // integer
settype ($undecided, 'double');
echo "is " .$undecided. " a double? " .is_double($undecided). "<br />"; // double
settype ($undecided, 'bool');
echo "is " .$undecided. " a boolean? " .is_bool($undecided). "<br />"; // boolean
?>

and line 2 ;)

 

<?php
$undecided = 3.14;
echo "Is " .$undecided. " a double? " .is_double($undecided). "<br />"; // double
settype ($undecided, 'string');
echo "Is " .$undecided. " a string? " .is_string($undecided). "<br />"; // string
settype ($undecided, 'integer');
echo "is " .$undecided. " an integer? " .is_int($undecided). "<br />"; // integer
settype ($undecided, 'double');
echo "is " .$undecided. " a double? " .is_double($undecided). "<br />"; // double
settype ($undecided, 'bool');
echo "is " .$undecided. " a boolean? " .is_bool($undecided). "<br />"; // boolean
?>

 

 

Although, I would take a look at this comment

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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