-- Ralph Schindler <[EMAIL PROTECTED]> wrote
(on Thursday, 01 February 2007, 09:49 AM -0600):
> Ok, its still the same 5.2.0 problem, I'll get with gavin and see what 
> solutions he has found to this bug in PHP.

I encountered this issue with Zend_View, and fixed it for the latest
release.

The only solution that works with <= 5.2.0 is to use public properties:

    public function __set($key, $value)
    {
        if ('_' != substr($key, 0, 1)) {
            $this->$key = $value;
        } else {
            throw new Exception('Cannot set protected/private class members');
        }
    }

Doing this emits no warnings or notices, and is fully backwards
compatible.  (Note: no need for __get(), __isset(), or __unset() with
this strategy; the properties are public. Also, changes were made in the
5.1.x series to ensure that creating new public properties on the fly
like this no longer raised E_STRICT messages, which is why this strategy
is valid now.)

ArrayAccess does not work, as there's a bug in it in 5.2.0 such that
empty() and isset() return incorrectly (fixed for 5.2.1). And, as you've
noted, overloading in 5.2.0 does not return references, so using __get()
in combination with __set() will fail for arrays (again, fixed in
5.2.1).

Basically, when ZF can raise the minimum supported version to 5.2.1,
we'll have more options for this sort of thing.

> Essentially, the guys as php decided to start returning things by value 
> instead of references (from what I understand), which means 
> Class::__set($n,$v); calls when called from something like 
> $s->property[] = something, the part before the [] needs to be 
> dereferenced.. Which they used to do, and now are not.
> 
> Will get back later with some results, even if its a note that says its 
> not possible in PHP 5.2.0
> 
> -Ralph
> 
> Philip Iezzi wrote:
> >Thanks Ralph
> >
> >It won't work yet on PHP 5.2.0 yet.
> >On a Windows box I'm getting the following notice:
> >
> >Notice: Indirect modification of overloaded property 
> >Zend_Session::$default has no effect in FlashMessage.php on line 87
> >
> >On a Unix box I'm not getting any notice at all, hasMessages() returns 
> >true and getMessages() is kinda empty...
> >FlashMessage Object ( [_namespace:protected] => default )
> >
> >On both systems I have set error_reporting(E_ALL)
> >pretty weird.
> >
> >Cheers,
> >philip
> >
> >Ralph Schindler wrote:
> >>Philip Iezzi wrote:
> >>>>Notice: Indirect modification of overloaded property
> >>>>Zend_Session::$default has no effect in FlashMessage.php on line 42
> >>>>
> >>>>line 42 (in add()):
> >>>>
> >>>>self::$_session->{$namespace}[] = $message;
> >>>It didn't work with Matthew's hack either...
> >>>http://weierophinney.net/matthew/archives/131-Overloading-arrays-in-PHP-5.2.0.html
> >>>
> >>>
> >>I did fix and tested and commented..
> >>
> >>http://svn.ralphschindler.com/repo/ZendFramework/library/FlashMessage.php
> >>
> >>please let me konw what you think.  This is a standalone version of
> >>FlashMessaging.. Ideally, there are aspects of this that should be
> >>dispatched from other areas, specifically Zend_Controller_Action, and
> >>from Zend_View_Helper..
> >>
> >>But I will address that within the next 2 days as I propose
> >>Zend_Controller_Action_Helper.  Having a component like that would allow
> >>for an easier and more seemless integration of FlashMessageing and other
> >>such related composite components.
> >>
> >>Also, I am pretty sure this shoudl work even in PHP 5.2.0* even due to
> >>its brokenness.
> >>
> >>Cheers, and let me know what you think!
> >>
> >>-ralph
> >>
> >
> 

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to