2009/11/16 Christian Seiler <chris...@gmx.net>:
> Hi,
>
> since a few months have passed since the last discussion on this topic
> and perhaps people had time to gather some experience with the current
> closure implementation in PHP 5.3 I'd like to restart the debate on
> $this in closures and object extension.
>
> Foreword: The discussion should center on the future behaviour of PHP 6
> ONLY. Whether or not a backport is even possible (binary compability
> etc.) or should even be done should be topic of a separate discussion
> and should *NOT* influence the decision. The ONLY goal of this
> discussion should be to agree on a SANE way of implementing $this for
> closures for PHP 6.
>
> I've updated the original RFC I wrote a tiny bit (I didn't change much):
>
> <http://wiki.php.net/rfc/closures/object-extension>
>
> The basic outline is the following:
>
>  * In the first section I explain the general issue.
>  * In the second section I show the proposals that were made on
>   internals@ before I wrote the RFC.
>  * In the third section I compare the approaches and explain why
>   the approaches (B) and (D) are inconsistent.
>  * In the fourth section I propose a new approach (bindTo) that
>   was only briefly discussed after the original RFC.
>
> Please read the complete RFC and try to understand the points I'm trying
> to make. If something is unclear, *please* ask first. In the past
> discussion I had the impression that a lot of people understood only
> partial aspects of the problem which made the discussion extremely
> noisy. I believe that is a disservice to the issue. However, now we have
> the huge advantage of NOT having an immanent deadline for a release. I
> hope this will enable a consensus on this issue.
>
> Discuss away!
>
> Regards,
> Christian
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I think the consistent mechanism is to have the binding done at
runtime and to be explicitly stated by the userland code.

$fn = function() use() bind($x) {
  // $this = whatever was bound, in this example $x
};

so, inside a class...

$fn = function() use() bind($this) {
  // $this would be the same as the $this of the class.
};

As for public/protected/private ...

$fn = function() use() bind() access(CLOSURE_PUBLIC |
CLOSURE_PROTECTED | CLOSURE_PRIVATE) {};

to control which properties/methods were available.

I'd be concerned about that this could be a shortcut to access
non-public properties/methods.

Richard.

-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to