ID:               47690
 User updated by:  crocodile2u at gmail dot com
 Reported By:      crocodile2u at gmail dot com
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: ubuntu 8.10
 PHP Version:      5.3CVS-2009-03-17 (snap)
 New Comment:

Ok, Thanks for a quick reply.

I would suggest adding that link to the wiki article. (I have just
registered in the wiki but there is no "Edit this page" button there for
me, guess it is a priviledge that I do not have).


Previous Comments:
------------------------------------------------------------------------

[2009-03-17 14:15:24] scott...@php.net

See http://wiki.php.net/rfc/closures/removal-of-this

------------------------------------------------------------------------

[2009-03-17 14:01:14] crocodile2u at gmail dot com

Description:
------------
http://wiki.php.net/rfc/closures in the "Interaction with OOP" section,
it is said that $this is accessible from within a lambda-function that
is declared in a method. This is not true for php-5.3.0beta.

Reproduce code:
---------------
<?php
// code completely taken from http://wiki.php.net/rfc/closures
class Example {
       private $search;
 
       public function __construct ($search) {
         $this->search = $search;
       }
 
       public function setSearch ($search) {
         $this->search = $search;
       }
 
       public function getReplacer ($replacement) {
         return function ($text) use ($replacement) {
           return str_replace ($this->search, $replacement, $text);
         };
       }
     }
 
     $example = new Example ('hello');
     $replacer = $example->getReplacer ('goodbye');
     echo $replacer ('hello world'); // goodbye world
     $example->setSearch ('world');
     echo $replacer ('hello world'); // hello goodbye

Expected result:
----------------
no errors occur

Actual result:
--------------
Fatal error: Using $this when not in object context in
/home/vbolshov/tmp/x.php on line 16


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47690&edit=1

Reply via email to