Unexpected NotFoundException when stored value is seen as FALSE by PHP #30

Closed
opened 2026-01-23 11:34:53 +01:00 by admin · 1 comment
Owner

Originally created by @nuxwin on GitHub (Jun 20, 2018).

@Ocramius

In the DBAL storage (find method), a check is made on SQL query result as follow:

        if (!$data) {
            throw new NotFoundException();
        }

That check is totally wrong... Why? If we have a stored value that PHP considere FALSE, a NotFoundException will be raised each time... Best would be to check for true FALSE value (strict check):

        if ($data === FALSE) {
            throw new NotFoundException();
        }

For our use case, we have the following storage:

MariaDB [imscp_new]> show columns from imscp_config;
+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| configName  | varchar(255) | NO   | PRI | NULL    |       |
| configValue | longtext     | NO   |     | NULL    |       |
+-------------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

MariaDB [imscp_new]> select * from imscp_config\G
*************************** 1. row ***************************
 configName: DATABASE_REVISION
configValue: 0
*************************** 2. row ***************************
 configName: PORT_DNS
configValue: 53;tcp;DNS;1;0.0.0.0
*************************** 3. row ***************************
 configName: PORT_FTP
configValue: 21;tcp;FTP;1;0.0.0.0
*************************** 4. row ***************************
 configName: PORT_HTTP
configValue: 80;tcp;HTTP;1;0.0.0.0
*************************** 5. row ***************************
 configName: PORT_HTTPS
configValue: 443;tcp;HTTPS;0;0.0.0.0
*************************** 6. row ***************************
 configName: PORT_IMAP
configValue: 143;tcp;IMAP;1;0.0.0.0
*************************** 7. row ***************************
 configName: PORT_IMAP-SSL
configValue: 993;tcp;IMAP-SSL;0;0.0.0.0
*************************** 8. row ***************************
 configName: PORT_IMSCP_DAEMON
configValue: 9876;tcp;i-MSCP-Daemon;1;127.0.0.1
*************************** 9. row ***************************
 configName: PORT_POP3
configValue: 110;tcp;POP3;1;0.0.0.0
*************************** 10. row ***************************
 configName: PORT_POP3-SSL
configValue: 995;tcp;POP3-SSL;0;0.0.0.0
*************************** 11. row ***************************
 configName: PORT_SMTP
configValue: 25;tcp;SMTP;1;0.0.0.0
*************************** 12. row ***************************
 configName: PORT_SMTP-SSL
configValue: 465;tcp;SMTP-SSL;0;0.0.0.0
*************************** 13. row ***************************
 configName: PORT_SSH
configValue: 22;tcp;SSH;1;0.0.0.0
*************************** 14. row ***************************
 configName: PORT_TELNET
configValue: 23;tcp;TELNET;1;0.0.0.0
Originally created by @nuxwin on GitHub (Jun 20, 2018). @Ocramius In the [DBAL storage (find method)](https://github.com/doctrine/KeyValueStore/blob/master/lib/Doctrine/KeyValueStore/Storage/DBALStorage.php#L145), a check is made on SQL query result as follow: ```php if (!$data) { throw new NotFoundException(); } ``` That check is totally wrong... Why? If we have a stored value that PHP considere `FALSE`, a **NotFoundException** will be raised each time... Best would be to check for true `FALSE` value (strict check): ```php if ($data === FALSE) { throw new NotFoundException(); } ``` For our use case, we have the following storage: ```sql MariaDB [imscp_new]> show columns from imscp_config; +-------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+-------+ | configName | varchar(255) | NO | PRI | NULL | | | configValue | longtext | NO | | NULL | | +-------------+--------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) MariaDB [imscp_new]> select * from imscp_config\G *************************** 1. row *************************** configName: DATABASE_REVISION configValue: 0 *************************** 2. row *************************** configName: PORT_DNS configValue: 53;tcp;DNS;1;0.0.0.0 *************************** 3. row *************************** configName: PORT_FTP configValue: 21;tcp;FTP;1;0.0.0.0 *************************** 4. row *************************** configName: PORT_HTTP configValue: 80;tcp;HTTP;1;0.0.0.0 *************************** 5. row *************************** configName: PORT_HTTPS configValue: 443;tcp;HTTPS;0;0.0.0.0 *************************** 6. row *************************** configName: PORT_IMAP configValue: 143;tcp;IMAP;1;0.0.0.0 *************************** 7. row *************************** configName: PORT_IMAP-SSL configValue: 993;tcp;IMAP-SSL;0;0.0.0.0 *************************** 8. row *************************** configName: PORT_IMSCP_DAEMON configValue: 9876;tcp;i-MSCP-Daemon;1;127.0.0.1 *************************** 9. row *************************** configName: PORT_POP3 configValue: 110;tcp;POP3;1;0.0.0.0 *************************** 10. row *************************** configName: PORT_POP3-SSL configValue: 995;tcp;POP3-SSL;0;0.0.0.0 *************************** 11. row *************************** configName: PORT_SMTP configValue: 25;tcp;SMTP;1;0.0.0.0 *************************** 12. row *************************** configName: PORT_SMTP-SSL configValue: 465;tcp;SMTP-SSL;0;0.0.0.0 *************************** 13. row *************************** configName: PORT_SSH configValue: 22;tcp;SSH;1;0.0.0.0 *************************** 14. row *************************** configName: PORT_TELNET configValue: 23;tcp;TELNET;1;0.0.0.0 ```
admin closed this issue 2026-01-23 11:34:53 +01:00
Author
Owner

@nuxwin commented on GitHub (Jun 20, 2018):

Issue is irrelevant.. Full object is stored, not only value...

@nuxwin commented on GitHub (Jun 20, 2018): Issue is irrelevant.. Full object is stored, not only value...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/KeyValueStore#30