php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64283 Attempting to store a closure in APC should either work or issue a warning
Submitted: 2013-02-23 01:46 UTC Modified: 2013-02-23 21:39 UTC
From: eric at wepay dot com Assigned:
Status: Closed Package: APC (PECL)
PHP Version: 5.4.12 OS: CentOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: eric at wepay dot com
New email:
PHP Version: OS:

 

 [2013-02-23 01:46 UTC] eric at wepay dot com
Description:
------------
Storing a closure in APC silently fails (or stores null), and retrieving it later 
ends up returning null which causes fun problems like "Function name must be a 
string in ..."

Use case: It's common to store app configuration in APC, and some configuration 
includes closures. If you have a closure in your config array and attempt to store 
it in APC, there are no warnings or errors; yet when fetching this value from APC 
it returns null.


Probably related to https://bugs.php.net/bug.php?id=63021 (I don't know if APC 
uses serialize or var_export, but it's the same general problem)

Test script:
---------------
$fn = function() { return 1; } ;

$ret = apc_store('test', $fn);

var_dump($ret); // NULL

$fetched = apc_fetch('test');

var_dump($fetched); // NULL

Expected result:
----------------
either a)

apc_store('key', $value_containing_closure) will throw an exception or issue some 
sort of warning (PHP notice?)

More accurately, var_export/serialize on a closure should probably handle this

or b)

it works (closures can be serialized/exported)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-23 10:32 UTC] laruence@php.net
I am not sure I got your point. but apc do trigger an exception:

Fatal error: Uncaught exception 'Exception' with message 'Serialization of 
'Closure' is not allowed' in /tmp/1.php:4
Stack trace:
#0 /tmp/1.php(4): apc_store('test', Object(Closure))
#1 {main}
  thrown in /tmp/1.php on line 4
 [2013-02-23 10:32 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2013-02-23 21:39 UTC] eric at wepay dot com
-Status: Feedback +Status: Closed
 [2013-02-23 21:39 UTC] eric at wepay dot com
My mistake - apparently display_errors was off in my console and I missed the 
uncaught exception in my local error logs when reproducing the issue. There's 
probably an issue in my codebase that caused the thrown exception to not get 
logged from the main application stack.

Thanks for looking though!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 04:01:29 2024 UTC