Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to API REST failed with php 8.x #28489

Open
1Fopresta opened this issue Feb 28, 2024 · 5 comments
Open

Access to API REST failed with php 8.x #28489

1Fopresta opened this issue Feb 28, 2024 · 5 comments
Labels
Bug This is a bug (something does not work as expected)

Comments

@1Fopresta
Copy link

1Fopresta commented Feb 28, 2024

Bug

Hi, with php 8.x, it is impossible to acces API
An error occured :

Fatal error: Uncaught TypeError: realpath(): Argument #1 ($path) must be of type string, array given in /var/www/vhosts/.../httpdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php:165

Environment Version

18.0.x and 19.0.0

Environment OS

Debian 11.9

Environment Web server

Nginx 1.24.0.2 and Apache 2.4.56

Environment PHP

8.x

Environment Database

MariaDB 10.5.23

Environment URL(s)

/api/index.php/explorer/

Expected and actual behavior

Fatal error: Uncaught TypeError: realpath(): Argument #1 ($path) must be of type string, array given in /var/www/vhosts/.../httpdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php:165
Stack trace:
#0 /var/www/vhosts/.../httpdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php(165): realpath()
#1 [internal function]: Luracast\Restler\AutoLoader->Luracast\Restler{closure}()
#2 /var/www/vhosts/.../httpdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php(163): array_map()
#3 /var/www/vhosts/.../httpdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php(38): Luracast\Restler\AutoLoader->__construct()
#4 /var/www/vhosts/.../httpdocs/api/index.php(95): Luracast\Restler\AutoLoader::instance()
#5 /var/www/vhosts/.../httpdocs/api/index.php(98): {closure}()
#6 {main}
thrown in /var/www/vhosts/.../httpdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php on line 165

realpath receive an array
With php 8, control error operator @ doesn't silent Fatal Error
In fact, this bug exist with php 7 but is not blocking with @

In Autoloader file (includes/restler/framework/Luracast/Restler/AutoLoader.php), i have replace (lines 153-158)

$paths = array_merge( $paths, array_values(static::loadFile( "$path{$slash}autoload_namespaces.php" )) );

by

foreach( array_values(static::loadFile("$path{$slash}autoload_namespaces.php")) as $aPath) { $paths = array_merge($paths,$aPath); }

And it works :)

Steps to reproduce the behavior

Install a new Dolibarr
Enabled API REST module
Acces to /api/index.php/explorer/

Attached files

No response

@1Fopresta 1Fopresta added the Bug This is a bug (something does not work as expected) label Feb 28, 2024
@JonBendtsen
Copy link
Contributor

I use 18.0.4 and I use the API

@1Fopresta
Copy link
Author

Same problem in 19.0.0

@JonBendtsen
Copy link
Contributor

@1Fopresta I use 19.0.0 now and I have no problem using the API explorer, would expect the regular API calls to work just as fine.

I currently run a pod with these images for my development setup.

localhost/podman-pause        5.0.0-dev-8a643c243-1710720000  288b8061dc18  13 days ago  1.14 MB
docker.io/tuxgasy/dolibarr    19.0.0-php8.2                   bfcc0eea82d4  13 days ago  798 MB
docker.io/library/phpmyadmin  latest                          79fbc663d551  2 weeks ago  575 MB
docker.io/library/mariadb     latest                          bc6434c28e9a  6 weeks ago  411 MB

@gertvermeersch
Copy link

gertvermeersch commented Jul 12, 2024

Same issue, it works on php7.4, but on 8 and above it throws the same error.

The fix of @1Fopresta works

@JonBendtsen
Copy link
Contributor

My container image from tuxgasy comes with PHP 8.1.20 and the API works.

root@dolipod:/var/www/html# php -v
PHP 8.1.20 (cli) (built: Jun 13 2023 12:02:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.20, Copyright (c) Zend Technologies

less -N AutoLoader.php

    153                                         $paths = array_merge(
    154                                                 $paths,
    155                                                 array_values(static::loadFile(
    156                                                         "$path{$slash}autoload_namespaces.php"
    157                                                 ))
    158                                         )

But the image is based on buster, aka Debian 10, not the version 11 that you use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a bug (something does not work as expected)
Projects
None yet
Development

No branches or pull requests

3 participants