|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-08-26 15:45 UTC] p3n4g473 at hotmail dot com
Description:
------------
I think PHP should include some sort of directive control system for determining what portions of a file are included when using the include()/include_once() and require()/require_once() functions from another file. For example, a directive to prevent inclusion of a block of code.
#NOINCLUDE
{
// some code that should not be included
}
The code inside that block would only be parsed when executing the script file directly.
Obviously, this is not a particularly important feature. However I would find this very useful for adding testing code to include files, so that the includes can be called directly to test them.
:-)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 18 05:00:01 2025 UTC |
Well, how about using the following idiom instead: <?php if (get_included_files() === 1) define('RUN_TESTS', true); … if (RUN_TESTS) { // some code that should not be included }i wouldn't put the test-code directly anyways our structure is that every class has to have an identical called file which contains the test code and is included at calltime of the method test() the test-suite running all that stuff is that way also aware when it returns -1 inteast 0/1 that the unit was not present and so they can be distributed independent as needed /** * Auto-Test Methode * * @return int * @access public */ public function test(): int { $basename = basename(__FILE__); if(file_exists("{$this->cl_api->CONTENTLOUNGE_BASEDIR}/autotests/$basename")) { return (int)require "{$this->cl_api->CONTENTLOUNGE_BASEDIR}/autotests/$basename"; } else { return -1; } }