|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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'
);
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 19:00:01 2025 UTC |
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/Замыкания/