Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

PHP Warning: call_user_func() expects…when Weakref enabled #4373

Closed
wants to merge 1 commit into from

4 participants

@mozen

PHP Warning: call_user_func() expects…when Weakref enabled

Hi.

When opening the ZendSkeletonApplication, it gave me a bunch of warnings and an error:

 PHP Warning:  call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /test/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php on line 472
 PHP Stack trace:
 PHP   1. {main}() /test/public/index.php:0
 PHP   2. Zend\\Mvc\\Application::init($configuration = *uninitialized*) /test/public/index.php:12
 PHP   3. Zend\\ModuleManager\\ModuleManager->loadModules() /test/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:238
 PHP   4. Zend\\EventManager\\EventManager->trigger($event = *uninitialized*, $target = *uninitialized*, $argv = *uninitialized*, $callback = *uninitialized*) /test/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:100
 PHP   5. Zend\\EventManager\\EventManager->triggerListeners($event = *uninitialized*, $e = *uninitialized*, $callback = *uninitialized*) /test/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:207
 PHP   6. call_user_func(*uninitialized*, *uninitialized*) /test/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:472

 PHP Warning:  call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /test/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php on line 472
 PHP Stack trace:
 PHP   1. {main}() /test/public/index.php:0
 PHP   2. Zend\\Mvc\\Application::init($configuration = *uninitialized*) /test/public/index.php:12
 PHP   3. Zend\\ModuleManager\\ModuleManager->loadModules() /test/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:238
 PHP   4. Zend\\EventManager\\EventManager->trigger($event = *uninitialized*, $target = *uninitialized*, $argv = *uninitialized*, $callback = *uninitialized*) /test/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:100
 PHP   5. Zend\\EventManager\\EventManager->triggerListeners($event = *uninitialized*, $e = *uninitialized*, $callback = *uninitialized*) /test/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:207
 PHP   6. call_user_func(*uninitialized*, *uninitialized*) /test/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php:472

 PHP Fatal error:  Uncaught exception 'Zend\\ModuleManager\\Exception\\RuntimeException' with message 'Module (Application) could not be initialized.' in /test/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:140
 Stack trace:
 #0 /test/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(81): Zend\\ModuleManager\\ModuleManager->loadModule('Application')
 #1 [internal function]: Zend\\ModuleManager\\ModuleManager->onLoadModules(Object(Zend\\ModuleManager\\ModuleEvent))
 #2 /test/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(472): call_user_func(Array, Object(Zend\\ModuleManager\\ModuleEvent))
 #3 /test/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\\EventManager\\EventManager->triggerListeners('loadModules', Object(Zend\\ModuleManager\\ModuleEvent), NULL)
 #4 /test/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(100): Zend\\EventManager\\EventManager->trigger('loadModules', Object(Zend\\ModuleManager\\ModuleManager), Object(Zend\\ModuleManager\\ModuleEvent))
 #5 /test/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(238): Zend\\ModuleManager\\ModuleManager->loadModules()
 #6 /test/public/index.php(12): Zend\\Mvc\\Application::init(Array)
 #7 {main}
   thrown in /test/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php on line 140

 
I installed Weakref from source:

 wget http://pecl.php.net/get/Weakref-0.2.2.tgz
 tar xzvf Weakref-0.2.2.tgz
 cd Weakref-0.2.2
 /usr/local/php/bin/phpize
 ./configure --with-php-config=/usr/local/php/bin/php-config
 make
 make install

 // phpinfo() output -> Weak References support Version: 0.0.1-alpha

 
I'm using:

 Zend Framework version 2.1.5

 PHP 5.4.14 (cli) (built: Apr 30 2013 20:11:38)
 Copyright (c) 1997-2013 The PHP Group
 Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
      with XCache v3.0.1, Copyright (c) 2005-2013, by mOo
      with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans
      with XCache Cacher v3.0.1, Copyright (c) 2005-2013, by mOo
      with XCache Coverager v3.0.1, Copyright (c) 2005-2013, by mOo

 
Please advise.

@mwillbanks
Collaborator

Could you please try current master? I believe this issue has been fixed.

@mozen

I tried dev-develop(2.3.0dev) and dev-master(2.2.0dev).
but issue has occurred.

@sasezaki

Hi, @mwillbanks .
one month ago, Weakref issue had resolved for ONLY EventManager test case with #3882 .
But ModuleManager's TestCase (& running ZendSkeltonApplication ) fails.

$ php -d extension=weakref.so /usr/bin/phpunit -c tests/phpunit.xml.dist tests/ZendTest/ModuleManager
There were 3 failures:

1) ZendTest\ModuleManager\Listener\ConfigListenerTest::testBadConfigValueThrowsInvalidArgumentException
Failed asserting that exception of type "Zend\ModuleManager\Exception\RuntimeException" matches expected exception "InvalidArgumentException". Message was: "Module (BadConfigModule) could not be initialized.".


2) ZendTest\ModuleManager\Listener\DefaultListenerAggregateTest::testDefaultListenerAggregateCanAttachItself
Failed asserting that an array contains 'ZendTest\ModuleManager\Listener\DefaultListenerAggregateTest'.

/home/kazusuke/dev/zendframework_zf2/tests/ZendTest/ModuleManager/Listener/DefaultListenerAggregateTest.php:99

3) ZendTest\ModuleManager\ModuleManagerTest::testCanNotLoadSomeObjectModuleWithoutIdentifier
Failed asserting that exception of type "PHPUnit_Framework_Error_Warning" matches expected exception "Zend\ModuleManager\Exception\RuntimeException". Message was: "call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object".
@weierophinney weierophinney Remove Weakref usage
- While it initially worked, usage has grown problematic as we've done more
  performance optimizations, and as Weakref itself has changed. What I found was
  that Weakref and the GC were cleaning up early, making listeners disappear -
  and thus making tests fail unexpectedly. Since we never want a listener to
  disappear, it makes sense to remove this functionality.
b7e2abf
@mwillbanks mwillbanks was assigned
@mwillbanks mwillbanks closed this pull request from a commit
@mwillbanks mwillbanks Merge branch 'hotfix/4373'
Close #4373
c91aaf3
@mwillbanks mwillbanks closed this in c91aaf3
@mwillbanks mwillbanks referenced this pull request from a commit
@mwillbanks mwillbanks Merge branch 'hotfix/4373' into develop
Forward port #4373
bde7f44
@weierophinney weierophinney referenced this pull request from a commit
@weierophinney weierophinney [#4373] Updated README
- Added note about removal of Weakref.
d21ccac
@mtymek mtymek referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@sasezaki sasezaki referenced this pull request in phalcon/cphalcon
Closed

[NFR] Events & Weak References #658

@ghost Unknown referenced this pull request from a commit
@mwillbanks mwillbanks Merge branch 'hotfix/4373'
Close #4373
3efdf45
@ghost Unknown referenced this pull request from a commit
@mwillbanks mwillbanks Merge branch 'hotfix/4373' into develop
Forward port #4373
ca0eee2
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney [#4373] Updated README
- Added note about removal of Weakref.
8b8dd2c
@gianarb gianarb referenced this pull request from a commit in zendframework/zend-eventmanager
@mwillbanks mwillbanks Merge branch 'hotfix/4373' a196779
@gianarb gianarb referenced this pull request from a commit in zendframework/zend-eventmanager
@mwillbanks mwillbanks Merge branch 'hotfix/4373' into develop c450aa4
@gianarb gianarb referenced this pull request from a commit in zendframework/zend-stdlib
@mwillbanks mwillbanks Merge branch 'hotfix/4373' 2cd6240
@gianarb gianarb referenced this pull request from a commit in zendframework/zend-stdlib
@mwillbanks mwillbanks Merge branch 'hotfix/4373' into develop 7b680aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 7, 2013
  1. @weierophinney

    Remove Weakref usage

    weierophinney authored
    - While it initially worked, usage has grown problematic as we've done more
      performance optimizations, and as Weakref itself has changed. What I found was
      that Weakref and the GC were cleaning up early, making listeners disappear -
      and thus making tests fail unexpectedly. Since we never want a listener to
      disappear, it makes sense to remove this functionality.
This page is out of date. Refresh to see the latest.
View
1  composer.json
@@ -23,7 +23,6 @@
"doctrine/annotations": "Doctrine Annotations >=1.0 for annotation features",
"ircmaxell/random-lib": "Fallback random byte generator for Zend\\Math\\Rand if OpenSSL/Mcrypt extensions are unavailable",
"ocramius/proxy-manager": "ProxyManager to handle lazy initialization of services",
- "pecl-weakref": "Implementation of weak references for Zend\\Stdlib\\CallbackHandler",
"zendframework/zendpdf": "ZendPdf for creating PDF representations of barcodes",
"zendframework/zendservice-recaptcha": "ZendService\\ReCaptcha for rendering ReCaptchas in Zend\\Captcha and/or Zend\\Form"
},
View
4 library/Zend/EventManager/EventManager.php
@@ -462,10 +462,6 @@ protected function triggerListeners($event, EventInterface $e, $callback = null)
foreach ($listeners as $listener) {
$listenerCallback = $listener->getCallback();
- if (!$listenerCallback) {
- $this->detach($listener);
- continue;
- }
// Trigger the listener's callback, and push its result onto the
// response collection
View
85 library/Zend/Stdlib/CallbackHandler.php
@@ -11,7 +11,6 @@
use Closure;
use ReflectionClass;
-use WeakRef;
/**
* CallbackHandler
@@ -40,12 +39,6 @@ class CallbackHandler
protected static $isPhp54;
/**
- * Is pecl/weakref extension installed?
- * @var bool
- */
- protected static $hasWeakRefExtension;
-
- /**
* Constructor
*
* @param string|array|object|callable $callback PHP callback
@@ -60,13 +53,6 @@ public function __construct($callback, array $metadata = array())
/**
* Registers the callback provided in the constructor
*
- * If you have pecl/weakref {@see http://pecl.php.net/weakref} installed,
- * this method provides additional behavior.
- *
- * If a callback is a functor, or an array callback composing an object
- * instance, this method will pass the object to a WeakRef instance prior
- * to registering the callback.
- *
* @param callable $callback
* @throws Exception\InvalidCallbackException
* @return void
@@ -77,44 +63,7 @@ protected function registerCallback($callback)
throw new Exception\InvalidCallbackException('Invalid callback provided; not callable');
}
- if (null === static::$hasWeakRefExtension) {
- static::$hasWeakRefExtension = class_exists('WeakRef');
- }
-
- // If pecl/weakref is not installed, simply store the callback and return
- if (!static::$hasWeakRefExtension) {
- $this->callback = $callback;
- return;
- }
-
- // If WeakRef exists, we want to use it.
-
- // If we have a non-closure object, pass it to WeakRef, and then
- // register it.
- if (is_object($callback) && !$callback instanceof Closure) {
- $this->callback = new WeakRef($callback);
- return;
- }
-
- // If we have a string or closure, register as-is
- if (!is_array($callback)) {
- $this->callback = $callback;
- return;
- }
-
- list($target, $method) = $callback;
-
- // If we have an array callback, and the first argument is not an
- // object, register as-is
- if (!is_object($target)) {
- $this->callback = $callback;
- return;
- }
-
- // We have an array callback with an object as the first argument;
- // pass it to WeakRef, and then register the new callback
- $target = new WeakRef($target);
- $this->callback = array($target, $method);
+ $this->callback = $callback;
}
/**
@@ -124,32 +73,7 @@ protected function registerCallback($callback)
*/
public function getCallback()
{
- $callback = $this->callback;
-
- // String callbacks -- simply return
- if (is_string($callback)) {
- return $callback;
- }
-
- // WeakRef callbacks -- pull it out of the object and return it
- if ($callback instanceof WeakRef) {
- return $callback->get();
- }
-
- // Non-WeakRef object callback -- return it
- if (is_object($callback)) {
- return $callback;
- }
-
- // Array callback with WeakRef object -- retrieve the object first, and
- // then return
- list($target, $method) = $callback;
- if ($target instanceof WeakRef) {
- return array($target->get(), $method);
- }
-
- // Otherwise, return it
- return $callback;
+ return $this->callback;
}
/**
@@ -162,11 +86,6 @@ public function call(array $args = array())
{
$callback = $this->getCallback();
- // WeakRef object will return null if the real object was disposed
- if (null === $callback) {
- return null;
- }
-
// Minor performance tweak, if the callback gets called more than once
if (!isset(static::$isPhp54)) {
static::$isPhp54 = version_compare(PHP_VERSION, '5.4.0rc1', '>=');
View
1  library/Zend/Stdlib/composer.json
@@ -13,7 +13,6 @@
},
"target-dir": "Zend/Stdlib",
"suggest": {
- "pecl-weakref": "Implementation of weak references for Stdlib\\CallbackHandler",
"zendframework/zend-servicemanager": "To support hydrator plugin manager usage"
},
"require": {
View
16 tests/ZendTest/EventManager/EventManagerTest.php
@@ -546,22 +546,6 @@ public function testTriggerCanTakeAnOptionalCallbackArgumentToEmulateTriggerUnti
$this->assertTrue($responses->stopped());
}
- public function testWeakRefsAreHonoredWhenTriggering()
- {
- if (!class_exists('WeakRef', false)) {
- $this->markTestSkipped('Requires pecl/weakref');
- }
-
- $functor = new TestAsset\Functor;
- $this->events->attach('test', $functor);
-
- unset($functor);
-
- $result = $this->events->trigger('test', $this, array());
- $message = $result->last();
- $this->assertNull($message);
- }
-
public function testDuplicateIdentifiersAreNotRegistered()
{
$events = new EventManager(array(__CLASS__, get_class($this)));
Something went wrong with that request. Please try again.