O
O
Outsider V.2016-02-10 22:33:35
PHP
Outsider V., 2016-02-10 22:33:35

Why doesn't realpath work on CentOS?

A simple autoloader that worked for me on Windows:

spl_autoload_register(
    function($class_address)
    {
        $path = __DIR__ . DIRECTORY_SEPARATOR . $class_address . '.php';

        require_once realpath($path);
    },
    true, true
);

Filled everything on CentOS - it gives an error that the class was not found. I'm starting to understand:
$path = __DIR__ . DIRECTORY_SEPARATOR . $class_addr . '.php';

        echo 'Original path is: ', $path . PHP_EOL;

        $path = realpath($path);

        echo 'After realpath: ' . var_export($path, true);

Original path is: /var/www/vendor/asoft\kernel\Kernel.php
After realpath: false

That is, realpath on Linux does not chew backslashes. What the heck? After all, the function was specially created to convert slashes to those needed for the current environment (on Windows, / was converted to \).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2016-02-10
@Audiophile

And where is it written that realpath should fix slashes?
On Linux, it is quite normal to have a file named "\kernel\Kernel.php"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question