(07-16-2016, 07:18 PM)davy_yg Wrote: Parse error: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php on line 34
A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION)
Filename: controllers/Cpages.php
Line Number: 34
Backtrace:
I have a new error that appearing that I am a little bit confuse.
Line 34 is: if ( ! function_exists('array_to_object'))
This is a little bit confusing to me. Why the error appearing?
Because an if statement is not valid in the body of a class. You can only define methods, properties, and constants in a class. An if statement would have to be either inside a method or outside of the class. One option would be to do something like this:
PHP Code:
protected function array_to_object($data)
{
if (function_exists('array_to_object')) {
return array_to_object($data);
}
// ... your existing array_to_object method here
}
Note that I've declared the method as protected, because leaving the visibility off of the method declaration is the same as declaring a public method, and public methods in controllers can be routed or accessed via the URL.