php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53610 closure and static private class member
Submitted: 2010-12-26 00:19 UTC Modified: 2015-05-06 15:40 UTC
Votes:6
Avg. Score:4.7 ± 0.7
Reproduced:5 of 5 (100.0%)
Same Version:5 (100.0%)
Same OS:5 (100.0%)
From: sergey dot s dot betke at novgaro dot ru Assigned: nikic (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.3.4 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: sergey dot s dot betke at novgaro dot ru
New email:
PHP Version: OS:

 

 [2010-12-26 00:19 UTC] sergey dot s dot betke at novgaro dot ru
Description:
------------
just one example:

class test {

private static $_domain;

static member() {
  add_settings_section(
     self::$_namespace . '_location_options',
     __('Location of your opensearch.xml file', self::$_domain),
     function () { ?>
        <p><?php _e('You can select location of your opensearch.xml file and his url, or leave automatic detection.', self::$_domain); ?></p>
     <?php },
     self::$_namespace . '_options_page'
  );
}

} 

and, this sample - not working. 

I honestly do not understand, and therefore the PHP developers do not consider the closure, created by the code of methods of class, as a class method. But it is implicitly "import" $this. 

Test script:
---------------
class test {

private static $_domain;

static test_member() {
  add_settings_section( // wordpress API
     self::$_namespace . '_location_options',
     __('Location of your opensearch.xml file', self::$_domain),
     function () { ?>
        <p><?php _e('You can select location of your opensearch.xml file and his url, or leave automatic detection.', self::$_domain); ?></p>
     <?php },
     self::$_namespace . '_options_page'
  );
}

} 



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-26 00:28 UTC] sergey dot s dot betke at novgaro dot ru
My article in Russian on this issue <a href="http://sergey-s-betke.blogs.novgaro.ru/lyambda-funkcii-zamykaniya-i-klassy-php">http://sergey-s-betke.blogs.novgaro.ru/lyambda-funkcii-zamykaniya-i-klassy-php</a>.
 [2011-04-12 17:18 UTC] ivan1986 at list dot ru
class Filter {
   public function filter($value = '') {
    return function() use ($value) {
     return $value;
    };
   }
}
class Test {
   private $_filter = null;
   public function test() {
    $filter = new Filter();
    $this->_filter = $filter->filter();
    echo 'filter data: ' . $this->_filter('my data'); //error
    $f = $this->_filter;
    echo 'filter data: ' . $f('my data'); //work
   }
}

$T= new Test();
$T->test();


http://www.askdev.ru/php/5450/Замыкания/
 [2015-05-06 15:40 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2015-05-06 15:40 UTC] nikic@php.net
Closure $this and scope binding was added in PHP 5.4 and I'd expect your code to work there.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 11:01:30 2024 UTC