ZF-8602: Setting = 4 in application.ini throws error

Issue Type: Bug Created: 2009-12-21T18:45:15.000+0000 Last Updated: 2010-01-12T13:29:28.000+0000 Status: Resolved Fix version(s): - 1.10.0 (27/Jan/10)

Reporter: Akeem Philbert (kanundrum) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Application_Resource

  • Zend_Log

Related issues: Attachments: - prioritydiff


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:

<pre class="highlight">
@@ -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'],

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


Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-12-22T08:48:16.000+0000

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).

Posted by Sergey Boroday (simpliest) on 2009-12-31T05:46:27.000+0000

I think that

<pre class="highlight">

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

Posted by Akeem Philbert (kanundrum) on 2009-12-31T06:04:27.000+0000

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.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-01-02T13:37:49.000+0000

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

<pre class="highlight">    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);

Posted by Akeem Philbert (kanundrum) on 2010-01-02T13:46:57.000+0000

that should have been array('filterParams' => array('priority' => '4')))); 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

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-01-02T14:45:32.000+0000

Adding quotes around the 4 makes no difference.

Posted by Akeem Philbert (kanundrum) on 2010-01-02T16:42:05.000+0000

The correct test case is:

<pre class="highlight">
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);

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

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-01-05T12:02:40.000+0000

Reassigning as agreed upon on irc

Posted by Matthew Weier O'Phinney (matthew) on 2010-01-12T13:29:28.000+0000

Fixed in trunk

Have you found an issue?

See the Overview section for more details.


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

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