Issues

ZF-8931: Use of error contol operator can cause conflicts with other classes

Description

I am using a database to store sessions and ran into a conflict between Zend_Db_Adapter_Sqlsrv and Zend_Session. I am testing version 1.1 of the SQL Server Driver for PHP to see how it works with UTF-8 text, and added CharacterSet = 'UTF-8' to the driver_options array. However, Zend_Db_Adapter_Sqlsrv attempts to resolve the configuration value as a constant first, and if undefined then to use the value as a string. This is achieved by using the error control operator to suppress warnings when calling constant():



                // A value may be a constant.
                if (is_string($value)) {
                    $constantValue = @constant(strtoupper($value));
                    if ($constantValue === null) {
                        $connectionInfo[$option] = $value;
                    } else {
                        $connectionInfo[$option] = $constantValue;
                    }
                }

The problem is that Zend_Session registers a custom error handler so it can convert PHP errors into exceptions, which means that it catches the warning even though it should be suppressed. There are two very simple fixes that can be made to correct this problem:

1) Given that there is already a mechanism for specifying constants in Zend_Config_Ini and Zend_Config_Xml, I don't think this "feature" is really necessary. The lines above could therefore be replaced with the following:


                // A value may be a constant.
                if (is_string($value)) {
                    $connectionInfo[$option] = $value;
                }

2) If this really is necessary for BC or whatever, it would be better to change the logic to first check if the constant has been defined before calling constant() rather than using the error control operator.



                // A value may be a constant.
                if (is_string($value)) {
                    $constantName = strtoupper($value);
                    if (defined($constantName)) {
                        $connectionInfo[$option] = constant($constantName);
                    } else {
                        $connectionInfo[$option] = $value;
                    }
                }

It looks like this issue is still in 1.10.0RC1. Is there a chance it can be fixed before 1.10 is officially released?

Comments

Fixed in trunk in r20626 and in 1.10 in r20630