Zend Framework

Setting resources.log.stream.filterParams.priority = 4 in application.ini throws error

Details

Description

The error is thrown because the constant doesn't exist in that class found in Zend_Log_Filter_Priority version 1.9.10 alpha. the potential fix is attached:

@@ -78,12 +78,12 @@
         ), $config);
 
         // Add support for constants
-        if (is_string($config['priority'])) {
-            $config['priority'] = constant($config['priority']);
+        if (!is_numeric($config['priority'])) {
+            $config['priority'] = constant("Zend_Log::".$config['priority']);
         }
 
         return new self(
-            $config['priority'], 
+            (int) $config['priority'],
             $config['operator']
         );
     }

The actual error

Warning: constant(): Couldn't find constant 4 in /var/www/wetawa/library/Zend/Log/Filter/Priority.php on line 82 Fatal error: Uncaught exception 'Zend_Log_Exception' with message 'Priority must be an integer' in /var/www/wetawa/library/Zend/Log/Filter/Priority.php:58 Stack trace: #0 /var/www/wetawa/library/Zend/Log/Filter/Priority.php(88): Zend_Log_Filter_Priority->__construct(NULL, NULL) #1 [internal function]: Zend_Log_Filter_Priority::factory(Array) #2 /var/www/wetawa/library/Zend/Log.php(201): call_user_func(Array, Array) #3 /var/www/wetawa/library/Zend/Log.php(154): Zend_Log->_constructFromConfig('filter', Array, 'Zend_Log_Filter') #4 /var/www/wetawa/library/Zend/Log.php(139): Zend_Log->_constructFilterFromConfig(Array) #5 /var/www/wetawa/library/Zend/Log.php(400): Zend_Log->_constructWriterFromConfig(Array) #6 /var/www/wetawa/library/Zend/Log.php(114): Zend_Log->addWriter(Array) #7 /var/www/wetawa/library/Zend/Application/Resource/Log.php(67): Zend_Log::factory(Array) #8 /var/www/wetawa/library/Zend/Application/Resource/Log.php(48): Zend_Application_Resource_Log->getLog() #9 /var/www/wetawa/library/Zend/Application/Bootstrap/B in /var/www/wetawa/library/Zend/Log/Filter/Priority.php on line 58

Activity

Hide
Dolf Schimmel (Freeaqingme) added a comment -

Thank you for reporting this issue. I am currently enjoying my holidays, but will fix it on January 1st. (unless I turn out to have (more) wifi available).

Show
Dolf Schimmel (Freeaqingme) added a comment - Thank you for reporting this issue. I am currently enjoying my holidays, but will fix it on January 1st. (unless I turn out to have (more) wifi available).
Hide
Sergey Boroday added a comment -

I think that

constant("Zend_Log::".$config['priority']);

is debatable.
Because such solution disallow us to use constants from other classes (e.g. own classes).

But both is_numeric and type casting to integer required. Because any atomic data goes from config goes as string and now we can't setup priority via number

Show
Sergey Boroday added a comment - I think that
constant("Zend_Log::".$config['priority']);
is debatable. Because such solution disallow us to use constants from other classes (e.g. own classes). But both is_numeric and type casting to integer required. Because any atomic data goes from config goes as string and now we can't setup priority via number
Hide
Akeem Philbert added a comment -

I added the class to find the constant to address the warning shown in the report as well, because the class Zend_Log_Filter_Priority has no constants defined. So this might require a bit of an architectural fix to accommodate developer defined constants. I should have noted that I'm using php 5.3.

Show
Akeem Philbert added a comment - I added the class to find the constant to address the warning shown in the report as well, because the class Zend_Log_Filter_Priority has no constants defined. So this might require a bit of an architectural fix to accommodate developer defined constants. I should have noted that I'm using php 5.3.
Hide
Dolf Schimmel (Freeaqingme) added a comment -

I tried to reproduce, but was not able. Please do provide (much) more information on how to reproduce. The used reproduction code:

public function testNumericLogStreamFilterParamsPriorityDoesNotFail() {
        $options = array('stream' =>
                        array('writerName'   => 'Stream',
                              'writerParams' => array('stream' => "php://memory",
                                                      'mode' => 'a'),
                        array('filterName' => 'Priority'),
                        array('filterParams' => array('priority' => 4))));
        $resource = new Zend_Application_Resource_Log($options);
        $resource->setBootstrap($this->bootstrap);
        $resource->init();
    }
Show
Dolf Schimmel (Freeaqingme) added a comment - I tried to reproduce, but was not able. Please do provide (much) more information on how to reproduce. The used reproduction code:
public function testNumericLogStreamFilterParamsPriorityDoesNotFail() {
        $options = array('stream' =>
                        array('writerName'   => 'Stream',
                              'writerParams' => array('stream' => "php://memory",
                                                      'mode' => 'a'),
                        array('filterName' => 'Priority'),
                        array('filterParams' => array('priority' => 4))));
        $resource = new Zend_Application_Resource_Log($options);
        $resource->setBootstrap($this->bootstrap);
        $resource->init();
    }
Hide
Akeem Philbert added a comment -

that should have been <code>array('filterParams' => array('priority' => '4'))));</code> since from the config ini it's a string. also note I'm using php 5.3. I'll try to write the failing testCase

Show
Akeem Philbert added a comment - that should have been <code>array('filterParams' => array('priority' => '4'))));</code> since from the config ini it's a string. also note I'm using php 5.3. I'll try to write the failing testCase
Hide
Dolf Schimmel (Freeaqingme) added a comment -

Adding quotes around the 4 makes no difference.

Show
Dolf Schimmel (Freeaqingme) added a comment - Adding quotes around the 4 makes no difference.
Hide
Akeem Philbert added a comment -

The correct test case is:

public function testNumericLogStreamFilterParamsPriorityDoesNotFail() {
        $options = array('stream' =>
                        array('writerName'   => 'Stream',
                              'writerParams' => array('stream' => "php://memory",
                                                      'mode' => 'a'),
                        'filterName' => 'Priority',
                        'filterParams' => array('priority' => '4')));
        $resource = new Zend_Application_Resource_Log($options);
        $resource->setBootstrap($this->bootstrap);
        $resource->init();
    }

The test case you are using never tests filters because your 'filterName' is wrapped in an array and line 138 is never hit in Zend/Log.php

Show
Akeem Philbert added a comment - The correct test case is:
public function testNumericLogStreamFilterParamsPriorityDoesNotFail() {
        $options = array('stream' =>
                        array('writerName'   => 'Stream',
                              'writerParams' => array('stream' => "php://memory",
                                                      'mode' => 'a'),
                        'filterName' => 'Priority',
                        'filterParams' => array('priority' => '4')));
        $resource = new Zend_Application_Resource_Log($options);
        $resource->setBootstrap($this->bootstrap);
        $resource->init();
    }
The test case you are using never tests filters because your 'filterName' is wrapped in an array and line 138 is never hit in Zend/Log.php
Hide
Dolf Schimmel (Freeaqingme) added a comment -

Reassigning as agreed upon on irc

Show
Dolf Schimmel (Freeaqingme) added a comment - Reassigning as agreed upon on irc
Hide
Matthew Weier O'Phinney added a comment -

Fixed in trunk

Show
Matthew Weier O'Phinney added a comment - Fixed in trunk

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: