php / web-php

The www.php.net site
http://www.php.net
Other
835 stars 534 forks source link

Subject: Documentation Issue - dirname(dirname(__FILE__)) Example on require_once page #935

Closed KevinGIRAULT closed 7 months ago

KevinGIRAULT commented 7 months ago

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

Hello,

I've identified an issue in the PHP documentation regarding the example that uses dirname(dirname(__FILE__)). The example is currently:

define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'/config.php');

// instead of:
<?php require_once('/var/www/public_html/config.php'); ?>

However, based on my understanding, dirname(dirname(__FILE__)) would ascend two directories, equivalent to the www directory in the given example, not public_html. As a result, __ROOT__.'/config.php' would be equivalent to www/config.php.

I propose updating the example to accurately reflect the behavior of dirname(dirname(__FILE__)):

define('__ROOT__', dirname(__FILE__));
require_once(__ROOT__.'/public_html/config.php');

Or

define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'/config.php');

Thank you for your attention to this matter.

kamil-tekiela commented 7 months ago

You are pointing to a user comment. We usually don't edit them. The example looks correct, although very outdated.