Jump to content

unexpected T_IF, expecting T_FUNCTION


Azyrus

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/261685-unexpected-t_if-expecting-t_function/
Share on other sites

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)

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)

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.