Req #38608 [Com]: File include control system feature request

From: Date: Mon, 12 Mar 2018 15:52:02 +0000
Subject: Req #38608 [Com]: File include control system feature request
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214307@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=38608&edit=1

 ID:                 38608
 Comment by:         spam2 at rhsoft dot net
 Reported by:        p3n4g473 at hotmail dot com
 Summary:            File include control system feature request
 Status:             Feedback
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   n/a
 PHP Version:        5.1.5
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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;
  }
 }


Previous Comments:
------------------------------------------------------------------------
[2018-03-12 15:47:14] cmb@php.net

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
  }

------------------------------------------------------------------------
[2006-08-26 15:45:03] 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.

:-)



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=38608&edit=1


Thread (4 messages)

« previous php.bugs (#214307) next »