Completed
Push — master ( 63f9e6...34eb4c )
by Kenji
10s
created

replacing/core/old/3.1.7-CodeIgniter.php (14 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 252 and the first side effect is on line 255.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
9
 * Copyright (c) 2014 - 2018, British Columbia Institute of Technology
10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
 * copies of the Software, and to permit persons to whom the Software is
16
 * furnished to do so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included in
19
 * all copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
 * THE SOFTWARE.
28
 *
29
 * @package	CodeIgniter
30
 * @author	EllisLab Dev Team
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
32
 * @copyright	Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
33
 * @license	http://opensource.org/licenses/MIT	MIT License
34
 * @link	https://codeigniter.com
35
 * @since	Version 1.0.0
36
 * @filesource
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
39
40
/**
41
 * System Initialization File
42
 *
43
 * Loads the base classes and executes the request.
44
 *
45
 * @package		CodeIgniter
46
 * @subpackage	CodeIgniter
47
 * @category	Front-controller
48
 * @author		EllisLab Dev Team
49
 * @link		https://codeigniter.com/user_guide/
50
 */
51
52
/**
53
 * CodeIgniter Version
54
 *
55
 * @var	string
56
 *
57
 */
58
	const CI_VERSION = '3.1.7';
59
60
/*
61
 * ------------------------------------------------------
62
 *  Load the framework constants
63
 * ------------------------------------------------------
64
 */
65
	if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
66
	{
67
		require_once(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
68
	}
69
70
	if (file_exists(APPPATH.'config/constants.php'))
71
	{
72
		require_once(APPPATH.'config/constants.php');
73
	}
74
75
/*
76
 * ------------------------------------------------------
77
 *  Load the global functions
78
 * ------------------------------------------------------
79
 */
80
	require_once(BASEPATH.'core/Common.php');
81
82
83
/*
84
 * ------------------------------------------------------
85
 * Security procedures
86
 * ------------------------------------------------------
87
 */
88
89 View Code Duplication
if ( ! is_php('5.4'))
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
{
91
	ini_set('magic_quotes_runtime', 0);
92
93
	if ((bool) ini_get('register_globals'))
94
	{
95
		$_protected = array(
96
			'_SERVER',
97
			'_GET',
98
			'_POST',
99
			'_FILES',
100
			'_REQUEST',
101
			'_SESSION',
102
			'_ENV',
103
			'_COOKIE',
104
			'GLOBALS',
105
			'HTTP_RAW_POST_DATA',
106
			'system_path',
107
			'application_folder',
108
			'view_folder',
109
			'_protected',
110
			'_registered'
111
		);
112
113
		$_registered = ini_get('variables_order');
114
		foreach (array('E' => '_ENV', 'G' => '_GET', 'P' => '_POST', 'C' => '_COOKIE', 'S' => '_SERVER') as $key => $superglobal)
115
		{
116
			if (strpos($_registered, $key) === FALSE)
117
			{
118
				continue;
119
			}
120
121
			foreach (array_keys($$superglobal) as $var)
122
			{
123
				if (isset($GLOBALS[$var]) && ! in_array($var, $_protected, TRUE))
124
				{
125
					$GLOBALS[$var] = NULL;
126
				}
127
			}
128
		}
129
	}
130
}
131
132
133
/*
134
 * ------------------------------------------------------
135
 *  Define a custom error handler so we can log PHP errors
136
 * ------------------------------------------------------
137
 */
138
	set_error_handler('_error_handler');
139
	set_exception_handler('_exception_handler');
140
	register_shutdown_function('_shutdown_handler');
141
142
/*
143
 * ------------------------------------------------------
144
 *  Set the subclass_prefix
145
 * ------------------------------------------------------
146
 *
147
 * Normally the "subclass_prefix" is set in the config file.
148
 * The subclass prefix allows CI to know if a core class is
149
 * being extended via a library in the local application
150
 * "libraries" folder. Since CI allows config items to be
151
 * overridden via data set in the main index.php file,
152
 * before proceeding we need to know if a subclass_prefix
153
 * override exists. If so, we will set this value now,
154
 * before any classes are loaded
155
 * Note: Since the config file data is cached it doesn't
156
 * hurt to load it here.
157
 */
158
	if ( ! empty($assign_to_config['subclass_prefix']))
159
	{
160
		get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
161
	}
162
163
/*
164
 * ------------------------------------------------------
165
 *  Should we use a Composer autoloader?
166
 * ------------------------------------------------------
167
 */
168 View Code Duplication
	if ($composer_autoload = config_item('composer_autoload'))
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
169
	{
170
		if ($composer_autoload === TRUE)
171
		{
172
			file_exists(APPPATH.'vendor/autoload.php')
173
				? require_once(APPPATH.'vendor/autoload.php')
174
				: log_message('error', '$config[\'composer_autoload\'] is set to TRUE but '.APPPATH.'vendor/autoload.php was not found.');
175
		}
176
		elseif (file_exists($composer_autoload))
177
		{
178
			require_once($composer_autoload);
179
		}
180
		else
181
		{
182
			log_message('error', 'Could not find the specified $config[\'composer_autoload\'] path: '.$composer_autoload);
183
		}
184
	}
185
186
/*
187
 * ------------------------------------------------------
188
 *  Start the timer... tick tock tick tock...
189
 * ------------------------------------------------------
190
 */
191
	$BM =& load_class('Benchmark', 'core');
192
	CIPHPUnitTestSuperGlobal::set_Global('BM', $BM);
193
	$BM->mark('total_execution_time_start');
194
	$BM->mark('loading_time:_base_classes_start');
195
196
/*
197
 * ------------------------------------------------------
198
 *  Instantiate the hooks class
199
 * ------------------------------------------------------
200
 */
201
	$EXT =& load_class('Hooks', 'core');
202
	CIPHPUnitTestSuperGlobal::set_Global('EXT', $EXT);
203
204
/*
205
 * ------------------------------------------------------
206
 *  Is there a "pre_system" hook?
207
 * ------------------------------------------------------
208
 */
209
	$EXT->call_hook('pre_system');
210
211
/*
212
 * ------------------------------------------------------
213
 *  Instantiate the config class
214
 * ------------------------------------------------------
215
 *
216
 * Note: It is important that Config is loaded first as
217
 * most other classes depend on it either directly or by
218
 * depending on another class that uses it.
219
 *
220
 */
221
	$CFG =& load_class('Config', 'core');
222
	CIPHPUnitTestSuperGlobal::set_Global('CFG', $CFG);
223
224
	// Do we have any manually set config items in the index.php file?
225
	if (isset($assign_to_config) && is_array($assign_to_config))
226
	{
227
		foreach ($assign_to_config as $key => $value)
228
		{
229
			$CFG->set_item($key, $value);
230
		}
231
	}
232
233
/*
234
 * ------------------------------------------------------
235
 * Important charset-related stuff
236
 * ------------------------------------------------------
237
 *
238
 * Configure mbstring and/or iconv if they are enabled
239
 * and set MB_ENABLED and ICONV_ENABLED constants, so
240
 * that we don't repeatedly do extension_loaded() or
241
 * function_exists() calls.
242
 *
243
 * Note: UTF-8 class depends on this. It used to be done
244
 * in it's constructor, but it's _not_ class-specific.
245
 *
246
 */
247
	$charset = strtoupper(config_item('charset'));
248
	ini_set('default_charset', $charset);
249
250 View Code Duplication
	if (extension_loaded('mbstring'))
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
251
	{
252
		define('MB_ENABLED', TRUE);
253
		// mbstring.internal_encoding is deprecated starting with PHP 5.6
254
		// and it's usage triggers E_DEPRECATED messages.
255
		@ini_set('mbstring.internal_encoding', $charset);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
256
		// This is required for mb_convert_encoding() to strip invalid characters.
257
		// That's utilized by CI_Utf8, but it's also done for consistency with iconv.
258
		mb_substitute_character('none');
259
	}
260
	else
261
	{
262
		define('MB_ENABLED', FALSE);
263
	}
264
265
	// There's an ICONV_IMPL constant, but the PHP manual says that using
266
	// iconv's predefined constants is "strongly discouraged".
267 View Code Duplication
	if (extension_loaded('iconv'))
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
268
	{
269
		define('ICONV_ENABLED', TRUE);
270
		// iconv.internal_encoding is deprecated starting with PHP 5.6
271
		// and it's usage triggers E_DEPRECATED messages.
272
		@ini_set('iconv.internal_encoding', $charset);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
273
	}
274
	else
275
	{
276
		define('ICONV_ENABLED', FALSE);
277
	}
278
279
	if (is_php('5.6'))
280
	{
281
		ini_set('php.internal_encoding', $charset);
282
	}
283
284
/*
285
 * ------------------------------------------------------
286
 *  Load compatibility features
287
 * ------------------------------------------------------
288
 */
289
290
	require_once(BASEPATH.'core/compat/mbstring.php');
291
	require_once(BASEPATH.'core/compat/hash.php');
292
	require_once(BASEPATH.'core/compat/password.php');
293
	require_once(BASEPATH.'core/compat/standard.php');
294
295
/*
296
 * ------------------------------------------------------
297
 *  Instantiate the UTF-8 class
298
 * ------------------------------------------------------
299
 */
300
	$UNI =& load_class('Utf8', 'core');
301
	CIPHPUnitTestSuperGlobal::set_Global('UNI', $UNI);
302
303
/*
304
 * ------------------------------------------------------
305
 *  Instantiate the URI class
306
 * ------------------------------------------------------
307
 */
308
	$URI =& load_class('URI', 'core');
309
	CIPHPUnitTestSuperGlobal::set_Global('URI', $URI);
310
311
/*
312
 * ------------------------------------------------------
313
 *  Instantiate the routing class and set the routing
314
 * ------------------------------------------------------
315
 */
316
	$RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL);
317
	CIPHPUnitTestSuperGlobal::set_Global('RTR', $RTR);
318
319
/*
320
 * ------------------------------------------------------
321
 *  Instantiate the output class
322
 * ------------------------------------------------------
323
 */
324
	$OUT =& load_class('Output', 'core');
325
	CIPHPUnitTestSuperGlobal::set_Global('OUT', $OUT);
326
327
/*
328
 * ------------------------------------------------------
329
 *	Is there a valid cache file? If so, we're done...
330
 * ------------------------------------------------------
331
 */
332
	if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE)
333
	{
334
		exit;
335
	}
336
337
/*
338
 * -----------------------------------------------------
339
 * Load the security class for xss and csrf support
340
 * -----------------------------------------------------
341
 */
342
	$SEC =& load_class('Security', 'core');
343
	CIPHPUnitTestSuperGlobal::set_Global('SEC', $SEC);
344
345
/*
346
 * ------------------------------------------------------
347
 *  Load the Input class and sanitize globals
348
 * ------------------------------------------------------
349
 */
350
	$IN	=& load_class('Input', 'core');
351
	CIPHPUnitTestSuperGlobal::set_Global('IN', $IN);
352
353
/*
354
 * ------------------------------------------------------
355
 *  Load the Language class
356
 * ------------------------------------------------------
357
 */
358
	$LANG =& load_class('Lang', 'core');
359
	CIPHPUnitTestSuperGlobal::set_Global('LANG', $LANG);
360
361
/*
362
 * ------------------------------------------------------
363
 *  Load the app controller and local controller
364
 * ------------------------------------------------------
365
 *
366
 */
367
	// Load the base controller class
368
	require_once BASEPATH.'core/Controller.php';
369
370
	/**
371
	 * Reference to the CI_Controller method.
372
	 *
373
	 * Returns current CI instance object
374
	 *
375
	 * @return CI_Controller
376
	 *
377
	 * modified by ci-phpunit-test
378
	 */
379
	function &get_instance()
0 ignored issues
show
The function get_instance() has been defined more than once; this definition is ignored, only the first definition in application/tests/_ci_ph...ng/core/CodeIgniter.php (L379-389) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
380
	{
381
		if (! CIPHPUnitTest::wiredesignzHmvcInstalled())
382
		{
383
			return CI_Controller::get_instance();
384
		}
385
		else
386
		{
387
			return CI::$APP;
388
		}
389
	}
390
391 View Code Duplication
	if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
392
	{
393
		require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
394
	}
395
396
	// Set a mark point for benchmarking
397
	$BM->mark('loading_time:_base_classes_end');
398
399
	// ci-phpunit-test
400
	return;
401
402
/*
403
 * ------------------------------------------------------
404
 *  Sanity checks
405
 * ------------------------------------------------------
406
 *
407
 *  The Router class has already validated the request,
408
 *  leaving us with 3 options here:
409
 *
410
 *	1) an empty class name, if we reached the default
411
 *	   controller, but it didn't exist;
412
 *	2) a query string which doesn't go through a
413
 *	   file_exists() check
414
 *	3) a regular request for a non-existing page
415
 *
416
 *  We handle all of these as a 404 error.
417
 *
418
 *  Furthermore, none of the methods in the app controller
419
 *  or the loader class can be called via the URI, nor can
420
 *  controller methods that begin with an underscore.
421
 */
422
423
	$e404 = FALSE;
424
	$class = ucfirst($RTR->class);
425
	$method = $RTR->method;
426
427 View Code Duplication
	if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php'))
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
428
	{
429
		$e404 = TRUE;
430
	}
431
	else
432
	{
433
		require_once(APPPATH.'controllers/'.$RTR->directory.$class.'.php');
434
435
		if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
436
		{
437
			$e404 = TRUE;
438
		}
439
		elseif (method_exists($class, '_remap'))
440
		{
441
			$params = array($method, array_slice($URI->rsegments, 2));
442
			$method = '_remap';
443
		}
444
		elseif ( ! method_exists($class, $method))
445
		{
446
			$e404 = TRUE;
447
		}
448
		/**
449
		 * DO NOT CHANGE THIS, NOTHING ELSE WORKS!
450
		 *
451
		 * - method_exists() returns true for non-public methods, which passes the previous elseif
452
		 * - is_callable() returns false for PHP 4-style constructors, even if there's a __construct()
453
		 * - method_exists($class, '__construct') won't work because CI_Controller::__construct() is inherited
454
		 * - People will only complain if this doesn't work, even though it is documented that it shouldn't.
455
		 *
456
		 * ReflectionMethod::isConstructor() is the ONLY reliable check,
457
		 * knowing which method will be executed as a constructor.
458
		 */
459
		elseif ( ! is_callable(array($class, $method)))
460
		{
461
			$reflection = new ReflectionMethod($class, $method);
462
			if ( ! $reflection->isPublic() OR $reflection->isConstructor())
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
463
			{
464
				$e404 = TRUE;
465
			}
466
	}
467
	}
468
469
	if ($e404)
470
	{
471
		if ( ! empty($RTR->routes['404_override']))
472
		{
473
			if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $error_class, $error_method) !== 2)
474
			{
475
				$error_method = 'index';
476
			}
477
478
			$error_class = ucfirst($error_class);
479
480
			if ( ! class_exists($error_class, FALSE))
481
			{
482
				if (file_exists(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php'))
483
				{
484
					require_once(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php');
485
					$e404 = ! class_exists($error_class, FALSE);
486
				}
487
				// Were we in a directory? If so, check for a global override
488
				elseif ( ! empty($RTR->directory) && file_exists(APPPATH.'controllers/'.$error_class.'.php'))
489
				{
490
					require_once(APPPATH.'controllers/'.$error_class.'.php');
491
					if (($e404 = ! class_exists($error_class, FALSE)) === FALSE)
492
					{
493
						$RTR->directory = '';
494
					}
495
				}
496
			}
497
			else
498
			{
499
				$e404 = FALSE;
500
			}
501
		}
502
503
		// Did we reset the $e404 flag? If so, set the rsegments, starting from index 1
504
		if ( ! $e404)
505
		{
506
			$class = $error_class;
507
			$method = $error_method;
508
509
			$URI->rsegments = array(
510
				1 => $class,
511
				2 => $method
512
			);
513
		}
514
		else
515
		{
516
			show_404($RTR->directory.$class.'/'.$method);
517
		}
518
	}
519
520
	if ($method !== '_remap')
521
	{
522
		$params = array_slice($URI->rsegments, 2);
523
	}
524
525
/*
526
 * ------------------------------------------------------
527
 *  Is there a "pre_controller" hook?
528
 * ------------------------------------------------------
529
 */
530
	$EXT->call_hook('pre_controller');
531
532
/*
533
 * ------------------------------------------------------
534
 *  Instantiate the requested controller
535
 * ------------------------------------------------------
536
 */
537
	// Mark a start point so we can benchmark the controller
538
	$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
539
540
	$CI = new $class();
541
542
/*
543
 * ------------------------------------------------------
544
 *  Is there a "post_controller_constructor" hook?
545
 * ------------------------------------------------------
546
 */
547
	$EXT->call_hook('post_controller_constructor');
548
549
/*
550
 * ------------------------------------------------------
551
 *  Call the requested method
552
 * ------------------------------------------------------
553
 */
554
	call_user_func_array(array(&$CI, $method), $params);
555
556
	// Mark a benchmark end point
557
	$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
558
559
/*
560
 * ------------------------------------------------------
561
 *  Is there a "post_controller" hook?
562
 * ------------------------------------------------------
563
 */
564
	$EXT->call_hook('post_controller');
565
566
/*
567
 * ------------------------------------------------------
568
 *  Send the final rendered output to the browser
569
 * ------------------------------------------------------
570
 */
571
	if ($EXT->call_hook('display_override') === FALSE)
572
	{
573
		$OUT->_display();
574
	}
575
576
/*
577
 * ------------------------------------------------------
578
 *  Is there a "post_system" hook?
579
 * ------------------------------------------------------
580
 */
581
	$EXT->call_hook('post_system');
582