Using version 1.8.4 of the framework, I am getting a PHP warning on a
login page I wrote. It is only a warning, so it could be suppressed,
and it happens prior to a redirect so the user never sees an error
message in any event, but I would like to eliminate the warning rather
than ignore it:

[29-Jul-2009 10:50:53] PHP Warning:  Invalid argument supplied for
foreach() in C:\ZendFramework\library\1.8\Zend\Acl.php on line 225

[29-Jul-2009 10:50:53] PHP Stack trace:

[29-Jul-2009 10:50:53] PHP   1. {main}() W:\Test\Intranet\public\index.php:0

[29-Jul-2009 10:50:53] PHP   2. Zend_Application->run()
W:\Test\Intranet\public\index.php:35

[29-Jul-2009 10:50:53] PHP   3.
Zend_Application_Bootstrap_Bootstrap->run()
C:\ZendFramework\library\1.8\Zend\Application.php:303

[29-Jul-2009 10:50:53] PHP   4. Zend_Controller_Front->dispatch()
C:\ZendFramework\library\1.8\Zend\Application\Bootstrap\Bootstrap.php:77

[29-Jul-2009 10:50:53] PHP   5.
Zend_Controller_Dispatcher_Standard->dispatch()
C:\ZendFramework\library\1.8\Zend\Controller\Front.php:936

[29-Jul-2009 10:50:53] PHP   6. Zend_Controller_Action->dispatch()
C:\ZendFramework\library\1.8\Zend\Controller\Dispatcher\Standard.php:288

[29-Jul-2009 10:50:53] PHP   7. LoginController->indexAction()
C:\ZendFramework\library\1.8\Zend\Controller\Action.php:512

[29-Jul-2009 10:50:53] PHP   8. Default_Model_Acl->loadRoles()
W:\Test\Intranet\lib\application\controllers\LoginController.php:56

[29-Jul-2009 10:50:53] PHP   9. Zend_Acl->removeRoleAll()
W:\Test\Intranet\lib\application\models\Acl.php:45


It appears that for some reason, $visitor['byRoleId'] is not an array
as is expected in Zend_Acl:

    public function removeRoleAll()
    {
        $this->_getRoleRegistry()->removeAll();

        foreach ($this->_rules['allResources']['byRoleId'] as
$roleIdCurrent => $rules) {
            unset($this->_rules['allResources']['byRoleId'][$roleIdCurrent]);
        }
        foreach ($this->_rules['byResourceId'] as $resourceIdCurrent
=> $visitor) {
            foreach ($visitor['byRoleId'] as $roleIdCurrent => $rules)
{  /* <--- LINE 225  */

unset($this->_rules['byResourceId'][$resourceIdCurrent]['byRoleId'][$roleIdCurrent]);
            }
        }

        return $this;
    }


To keep the ACL lighter, my class loads from a database only the roles
which the current user inherits. The first line of my loadRoles()
method calls removeRoleAll() to clear out any roles previously added
before continuing.(This should really only be when a user logs in,
since the page initially loads the ACL for a generic unauthenticated
user before the login controller authenticates the credentials passed.
If the credentials are valid, the controller reloads the ACL for the
authenticated user.)

Is this a bug, or am I using this incorrectly?

Andrew

Reply via email to