ID:               47690
 Updated by:       scott...@php.net
 Reported By:      crocodile2u at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: ubuntu 8.10
 PHP Version:      5.3CVS-2009-03-17 (snap)
 New Comment:

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


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

[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