Doc #80149 [Opn->Fbk]: Mutually included files

From: Date: Fri, 25 Sep 2020 13:05:04 +0000
Subject: Doc #80149 [Opn->Fbk]: Mutually included files
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17907@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80149&edit=1

 ID:                 80149
 Updated by:         danack@php.net
 Reported by:        marcio dot a dot siena at gmail dot com
 Summary:            Mutually included files
-Status:             Open
+Status:             Feedback
 Type:               Documentation Problem
 Package:            Documentation problem
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

"but the require_once in b.php does not re-include a.php. But that behavior is not explicitly
stated in the relevant documentation pages:"


From the manual https://www.php.net/manual/en/function.require-once.php:
"The require_once statement is identical to require except PHP will check if the file has
already been included, and if so, not include (require) it again."

That is pretty clear to me. If you don't think it is, can you suggest where and how it should
be documented?


Previous Comments:
------------------------------------------------------------------------
[2020-09-25 13:01:09] marcio dot a dot siena at gmail dot com

More complete scripts:

a1.php:
------

<?php

    echo "INSIDE a1.php <br><br>";
    require_once($_SERVER['DOCUMENT_ROOT'] . "/b1.php");

?>


b1.php:
------
<?php

    echo "INSIDE b1.php <br><br>";
    require_once($_SERVER['DOCUMENT_ROOT'] . "/a1.php");

?>

------------------------------------------------------------------------
[2020-09-25 12:55:36] marcio dot a dot siena at gmail dot com

Description:
------------
The documentation does not talk about mutually included/required files.

Mutually included/required files: a.php requires (once) b.php, and b.php requires (once) a.php.

a.php is the "master" file. b.php is the included file. But what if b.php needs to
re-include a.php?

Use case: legacy application being refactored, tons of cases. HTTP requests may come to a.php or to
b.php, but both scripts depends upon each other.

When that occurs, as one may expected, a.php includes b.php, but the require_once in b.php does not
re-include a.php.

But that behavior is not explicitly stated in the relevant documentation pages:

- https://www.php.net/manual/en/function.require-once.php
- https://www.php.net/manual/en/function.include-once.php

So one must make tests to be sure about PHP's true behavior.

My proposition: state that behavior clearly in the docs.


Test script:
---------------
- in a.php: require_once('b.php');

- in b.php: require_once('a.php');




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



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


Thread (10 messages)

« previous php.doc.bugs (#17907) next »