Azyrus Posted April 27, 2012 Share Posted April 27, 2012 Hello everyone I'm modifying an open source software called phpScheduleIt, I'm trying to change the machid function based on the $type variable and I'm getting this error below: Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION in C:\xampp\htdocs\phpScheduleIt\lib\Reservation.class.php on line 1122 1122 if ($type == RES_TYPE_ADD) 1123 function get_machid() { 1124 return $this->resource->get_property('machid'); 1125 } 1126 if ($type == RES_TYPE_MODIFY) 1127 function get_machid() { 1128 return $this->machid; 1129 } I don't understand why this isn't working :\ phpSchedule it is a really great free open source scheduling software if anyone is interested, full credits to Nick Korbel. http://php.brickhost.com Quote Link to comment https://forums.phpfreaks.com/topic/261685-unexpected-t_if-expecting-t_function/ Share on other sites More sharing options...
Zane Posted April 27, 2012 Share Posted April 27, 2012 The error says unexpected IF, meaning it was expecting something else.. The problem most likely lies above the code you provided. Quote Link to comment https://forums.phpfreaks.com/topic/261685-unexpected-t_if-expecting-t_function/#findComment-1340973 Share on other sites More sharing options...
requinix Posted April 27, 2012 Share Posted April 27, 2012 You can't put if blocks directly inside a class definition. Instead, put them inside the get_machid() function like function get_machid() { if ($this->type == RES_TYPE_ADD) { return $this->resource->get_property('machid'); } else if ($this->type == RES_TYPE_MODIFY) { return $this->machid; } } (assuming that the "type" variable is a member of the Reservation class and not, say, a function parameter you haven't mentioned) Quote Link to comment https://forums.phpfreaks.com/topic/261685-unexpected-t_if-expecting-t_function/#findComment-1340974 Share on other sites More sharing options...
Azyrus Posted April 27, 2012 Author Share Posted April 27, 2012 Requinix I love you! You are my HERO! This works 100% You can't put if blocks directly inside a class definition. Instead, put them inside the get_machid() function like function get_machid() { if ($this->type == RES_TYPE_ADD) { return $this->resource->get_property('machid'); } else if ($this->type == RES_TYPE_MODIFY) { return $this->machid; } } (assuming that the "type" variable is a member of the Reservation class and not, say, a function parameter you haven't mentioned) Quote Link to comment https://forums.phpfreaks.com/topic/261685-unexpected-t_if-expecting-t_function/#findComment-1340977 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.