Welcome Guest, Not a member yet? Register   Sign In
retrieving and showing data
#18

(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.
Reply


Messages In This Thread
retrieving and showing data - by davy_yg - 07-12-2016, 07:34 AM
RE: retrieving and showing data - by arma7x - 07-12-2016, 07:44 AM
RE: retrieving and showing data - by davy_yg - 07-12-2016, 07:53 AM
RE: retrieving and showing data - by arma7x - 07-12-2016, 08:09 AM
RE: retrieving and showing data - by mwhitney - 07-12-2016, 08:26 AM
RE: retrieving and showing data - by rtenny - 07-12-2016, 09:18 AM
RE: retrieving and showing data - by davy_yg - 07-12-2016, 09:30 PM
RE: retrieving and showing data - by rtenny - 07-13-2016, 09:19 AM
RE: retrieving and showing data - by InsiteFX - 07-12-2016, 07:10 PM
RE: retrieving and showing data - by InsiteFX - 07-13-2016, 07:42 AM
RE: retrieving and showing data - by InsiteFX - 07-13-2016, 10:14 AM
RE: retrieving and showing data - by davy_yg - 07-13-2016, 06:31 PM
RE: retrieving and showing data - by davy_yg - 07-13-2016, 06:36 PM
RE: retrieving and showing data - by InsiteFX - 07-14-2016, 03:08 AM
RE: retrieving and showing data - by arma7x - 07-14-2016, 03:46 AM
RE: retrieving and showing data - by Ivo Miranda - 07-14-2016, 04:13 AM
RE: retrieving and showing data - by davy_yg - 07-16-2016, 07:18 PM
RE: retrieving and showing data - by mwhitney - 07-18-2016, 01:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB