Reputation: 13412
I was wondering, if it's possible not to repeat your self when using if statements in PHP. The following is the part of my spl_autoload_register
function, e.g.:
if (is_file(Core::Config('plugins_path') . '/' . strtolower($required_class) . '.class.php'))
{
require_once (Core::Config('plugins_path') . '/' . strtolower($required_class) . '.class.php');
}
Is there a way to write it familiar to:
if (is_file(Core::Config('plugins_path') . '/' . strtolower($required_class) . '.class.php'))
{
require_once ( this );
}
in order not to duplicate exactly the same line of the code?
The example above is not working.. Is there a way really?
Upvotes: 0
Views: 52
Reputation: 13412
Based on the idea offered by Pietu, I'd rather shorten it to:
$file = Core::Config('plugins_path') . '/' . strtolower( $required_class ) . '.class.php';
is_file( $file ) && require_once ( $file );
Upvotes: 0
Reputation: 6809
Not exactly as you described. But you can shrink the code with a variable.
$file = Core::Config('plugins_path') . '/' . strtolower($required_class) . '.class.php';
if (is_file($file))
{
require_once ( $file );
}
Upvotes: 2