index.php sets the current working directory to the root directory of the application (a folder containing composer.json , init_autoloader.php , etc.)
Until you call chdir to another place in your application, you can call getcwd() and it will always return the path to your application root.
Since the shared folder is relative to this, you can get the path using ...
$publicDir = getcwd() . '/public';
Crisp source share