Carlton Posted August 20, 2010 Share Posted August 20, 2010 I'm getting a strange error for this code, but i'm unable to find out what's wrong, the error is below: Parse error: parse error, expecting `'&'' or `T_VARIABLE' in on line 12 Here's the code: function CMySQL_Create($Username, $Password, bool:$md5 = true) { switch($md5) { case false: { mysql_query("INSERT INTO " . $ACCOUNT_TABLE . " (" . $USERNAME_FIELD . ", " . $PASSWORD_FIELD . ") VALUES('" . mysql_real_escape_string($Username) . "', '" . mysql_real_escape_string($Password) . "')") or die(mysql_error()); } case true: { mysql_query("INSERT INTO " . $ACCOUNT_TABLE . " (" . $USERNAME_FIELD . ", " . $PASSWORD_FIELD . ") VALUES('" . mysql_real_escape_string($Username) . "', md5('" . mysql_real_escape_string($Password) . "'))") or die(mysql_error()); } } } The line of this error is: function CMySQL_Create($Username, $Password, bool:$md5 = true) { Any clue? Link to comment https://forums.phpfreaks.com/topic/211320-explanation-why-this-error-is-occurring/ Share on other sites More sharing options...
AbraCadaver Posted August 20, 2010 Share Posted August 20, 2010 What is this? bool:$md5 = true That's not valid. What are you trying to do, type hint? You can only type hint array or object types, and the only default value they can have is NULL. Link to comment https://forums.phpfreaks.com/topic/211320-explanation-why-this-error-is-occurring/#findComment-1101842 Share on other sites More sharing options...
AbraCadaver Posted August 20, 2010 Share Posted August 20, 2010 Sorry, short reply at first. If you want to force it boolean then type cast and use something like: switch( (bool) $MD5 ) { Or throw an exception and use something like: if(!is_bool($MD5)) { throw new Exception('Parameter three must be boolean!'); } Link to comment https://forums.phpfreaks.com/topic/211320-explanation-why-this-error-is-occurring/#findComment-1101864 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.