Issues

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

Issue Type: Bug Created: 2010-01-25T09:57:51.000+0000 Last Updated: 2010-01-25T13:30:52.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Andrew Ballard (aballard) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db

Related issues: Attachments:

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():

<pre class="highlight">

                // 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:
<pre class="highlight">
                // A value may be a constant.
                if (is_string($value)) {
                    $connectionInfo[$option] = $value;
                }
  1. 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.
<pre class="highlight">

                // 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

Posted by Ralph Schindler (ralph) on 2010-01-25T13:30:51.000+0000

Fixed in trunk in r20626 and in 1.10 in r20630

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts