Actually his response is asinine by stating that "This is unfortunately a major flaw in the coding used for the script, and has been seen before on anything utilising realpath, which doesn't show the absolute path correctly."
This is NOT a bug in PHP – at least not in any 5.4.x or alter version. Indeed there was a bug in old versions of PHP 5.2 and probably older concerning symlinks. However, no such bug exists anymore.
Furthermore, we are using __DIR__, not realpath(). Using __DIR__ is NOT a bad programming practice unless you consider the STANDARD programming practice of Joomla!, WordPress, Drupal, Magento, Moodle, PrestaShop and other major PHP CMS and e-commerce solution as well as the programming practices of the major PHP frameworks (Symfony, Laravel, Zend Framework) which power the sites of Fortune 500 companies "majorly flawed". The only major flaw here lies in this tech's complete lack of PHP knowledge.
Let me remind you that before PHP 5.3 developers (and all PHP products!!!) had to use the construct realpath(dirname(__FILE__)) to get the
equivalent of what __DIR__ contains since PHP 5.3. Indeed, the PHP community decided that the construct is A Bad Idea™ not because of the use of realpath but because of 1. bad performance and 2. certain servers using a borked CGI setup populating __FILE__ with a relative path (there was even a php.ini switch to fix that issue). And that's why we, along with every PHP developer out there, replaced those constructs with a simple reference to the __DIR__ magic constant. That happened nearly 5 years ago when we could finally drop PHP 5.2 support.
I can tell you what is 99% likely to be going on because
I've seen that again. They are mounting two different partitions (presumably on different physical disks / SANs) into /home and /home2 because their server's main hard drive maxed out. Their first mistake is that they are not using
LVM to properly extend the capacity of their server. The other mistake is that they resort to hardlinks to make the /home2 directories appear as subdirectories of /home. They had to do that otherwise their OS wouldn't see the user accounts stored in /home2. Since PHP –and any process that doesn't explicitly look for hardlinks– can't see the difference between /home/yourUser and /home2/yourUser it reports a path under /home as the full filesystem path (using the __DIR__ constant). However, they are also using
open_basedir to limit access to /home2/yourUser.
So because your host doesn't understand how Linux or PHP work they have screwed up their server setup, big time!
I would like to remind that so-called "support tech" who replied to you that the
actual code used to determine the path is the following and just the following:
define('APATH_BASE', __DIR__);
$parts = explode(DIRECTORY_SEPARATOR, APATH_BASE);
array_pop($parts);
define('APATH_ROOT', implode(DIRECTORY_SEPARATOR, $parts));
The APATH_ROOT constant, derived solely from __DIR__ (introduced in PHP 5.3.0), is what is being displayed. The only reason __DIR__ contains the wrong path is because your host doesn't know how Linux works and borked the server capacity extension by doing the same WRONG thing hosts were doing in the early '00s. Let me remind you that Linux LVM 2.x
has been around since 2004. You'd think that in 12 years your host might have figured it out...
So apparently the "support techs" they employ a. don't know how their server work b. don't know how PHP works and c. can't read PHP code. Yet they feel entitled to comment on how we write our code. I'd like to remind everyone reading this exactly how
Joomla! itself, in the administrator application, determines the path to your site's root which lets it load com_login that eventually lets you log in etc:
define('JPATH_BASE', __DIR__);
$parts = explode(DIRECTORY_SEPARATOR, JPATH_BASE);
array_pop($parts);
// Defines.
define('JPATH_ROOT', implode(DIRECTORY_SEPARATOR, $parts));
The code is split between administrator/index.php and administrator/includes/defines.php.
Based on the fact that Joomla! runs fine on 3% of the
entire freaking Internet of millions upon millions of sites and we're using the same code as Joomla! we can very safely conclude that your host has no idea how their server, Linux, PHP and Joomla! work. I would STRONGLY recommend switching to a host that knows what they're doing. In no particular order I recommend CloudAccess.net, SiteGround, Rochen and InMotion Hosting.
Nicholas K. Dionysopoulos
Lead Developer and Director
🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!