[GH-ISSUE #266] Use of undefined constant warning in php7.3 #192

Closed
opened 2026-03-02 15:56:39 +03:00 by kerem · 3 comments
Owner

Originally created by @amurad on GitHub (Dec 18, 2019).
Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/266

I am running in debian with nginx 16.1 and php7.3. I am getting following warning when trying to open image or pdf file:

Warning

: Use of undefined constant online_viewer - assumed 'online_viewer' (this will throw an Error in a future version of PHP) in /srv/www/index.php on line 1387

Originally created by @amurad on GitHub (Dec 18, 2019). Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/266 I am running in debian with nginx 16.1 and php7.3. I am getting following warning when trying to open image or pdf file: > **Warning**: Use of undefined constant online_viewer - assumed 'online_viewer' (this will throw an Error in a future version of PHP) in /**srv/www/index.php** on line **1387**
kerem 2026-03-02 15:56:39 +03:00
Author
Owner

@alan67160 commented on GitHub (Jan 3, 2020):

I'm using Ubuntu Server 19.10 at Raspberry Pi 4B(4GB Ram/128GB SD card) with Nginx 1.16.1 and php7.3-fpm, but I can't see any error.

<!-- gh-comment-id:570725838 --> @alan67160 commented on GitHub (Jan 3, 2020): I'm using Ubuntu Server 19.10 at Raspberry Pi 4B(4GB Ram/128GB SD card) with Nginx 1.16.1 and php7.3-fpm, but I can't see any error.
Author
Owner

@yumyo commented on GitHub (Jan 22, 2020):

I see all the warnings on PHP 5.5.9 when setting error_reporting to true. I assume the same should happen for PHP 7.3 as the correct way to set arrays as constant values is to serialize and unserialize the array. https://stackoverflow.com/a/19444381
So changing line 359 to:
defined('FM_EXCLUDE_ITEMS') || define('FM_EXCLUDE_ITEMS', serialize($exclude_items));

and line 2298 to:
if(!in_array($file, unserialize(FM_EXCLUDE_ITEMS)) && !in_array("*.$ext", unserialize(FM_EXCLUDE_ITEMS))) {

Solve all fo the notices and warnings at once.

<!-- gh-comment-id:577294133 --> @yumyo commented on GitHub (Jan 22, 2020): I see all the warnings on PHP 5.5.9 when setting error_reporting to true. I assume the same should happen for PHP 7.3 as the correct way to set arrays as constant values is to serialize and unserialize the array. https://stackoverflow.com/a/19444381 So changing line 359 to: `defined('FM_EXCLUDE_ITEMS') || define('FM_EXCLUDE_ITEMS', serialize($exclude_items));` and line 2298 to: ` if(!in_array($file, unserialize(FM_EXCLUDE_ITEMS)) && !in_array("*.$ext", unserialize(FM_EXCLUDE_ITEMS))) {` Solve all fo the notices and warnings at once.
Author
Owner

@yumyo commented on GitHub (Jan 22, 2020):

Actually, In PHP 7, array values are also accepted, so you can either apply the fix above or upgrade PHP if possible. But it also seems that serializing and unserializing it is still a good practice for constant values.

<!-- gh-comment-id:577295603 --> @yumyo commented on GitHub (Jan 22, 2020): Actually, In PHP 7, array values are also accepted, so you can either apply the fix above or upgrade PHP if possible. But it also seems that serializing and unserializing it is still a good practice for constant values.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tinyfilemanager#192
No description provided.