Re: Coding standards - inclusion

From: Date: Tue, 13 Oct 2009 09:49:12 +0000
Subject: Re: Coding standards - inclusion
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-52934@lists.php.net to get a copy of this message
On 13/10/2009 7:54 PM, Christian Weiske wrote:
Hello Eric,
From http://pear.php.net/manual/en/standards.including.php: "Anywhere you are unconditionally including a class file, use require_once. Anywhere you are conditionally including a class file (for example, factory methods), use include_once." Out of curiosity, why is this the case? What benefits does it offer?
A failed require leads to a fatal error which is not catchable by code. In you library, you should include a file and throw an exception if that failed - this is programmatically verifiable.
Thank-you for the response, and good point. Is there some recommended way of checking success? I thought of this: if (@include 'test.php') echo 'yes'; else throw new Exception('no'); Some say the error control operator is quite slow; is there some advantage to the above vs: if (file_exists('test.php')) require 'test.php'; else throw new Exception('no'); Cheers, Eric

« previous php.pear.dev (#52934) next »