php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62699 Weird behavior with traits and APC enabled
Submitted: 2012-07-30 18:59 UTC Modified: 2013-02-18 00:35 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: franssen dot roland at gmail dot com Assigned:
Status: No Feedback Package: APC (PECL)
PHP Version: 5.4.5 OS: Ubuntu
Private report: No CVE-ID: None
 [2012-07-30 18:59 UTC] franssen dot roland at gmail dot com
Description:
------------
Hi,

I'm getting very weird behavior using traits with APC (3.1.11) enabled.

Test script:
---------------
<?php
trait A {
    public function test() {
        var_dump(__TRAIT__);
    }
}
class Foo {
    use A {
        A::test as test2;
    }
    public function test() {
        var_dump(__CLASS__);
    }
}
$foo = new Foo;
$foo->test();
$foo->test2();

Expected result:
----------------
string(3) "Foo"
string(1) "A" 

Actual result:
--------------
page load (basicly direct after restarting apache):
string(3) "Foo"
string(1) "A" 

after page refresh:
string(3) "Foo"
Fatal error: Call to undefined method Foo::test2() in /var/www/test.php on line 17

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-30 21:27 UTC] ab@php.net
When PHP compiled in debug mode, I have this trace with the snippet already with 
the first request

#0  0x00132416 in __kernel_vsyscall ()
#1  0x001d81ef in __GI_raise (sig=6) at 
../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2  0x001db835 in __GI_abort () at abort.c:91
#3  0x001d1095 in __assert_fail_base (fmt=0x30a8b8 "%s%s%s:%u: %s%sAssertion 
`%s' failed.\n%n", 
    assertion=0x196b140 "op_type == (1<<0) || op_type == (1<<2) || op_type == 
(1<<4) || op_type == (1<<1) || op_type == (1<<3)", file=0x196b09c 
"/home/weltling/dws/src/apc_trunk/apc_compile.c", line=394, function=0x196b6f2 
"my_check_znode")
    at assert.c:94
#4  0x001d1147 in __GI___assert_fail (
    assertion=0x196b140 "op_type == (1<<0) || op_type == (1<<2) || op_type == 
(1<<4) || op_type == (1<<1) || op_type == (1<<3)", file=0x196b09c 
"/home/weltling/dws/src/apc_trunk/apc_compile.c", line=394, function=0x196b6f2 
"my_check_znode")
    at assert.c:103
#5  0x01958cfd in my_check_znode (op_type=0 '\000', ctxt=0xbfffb854) at 
/home/weltling/dws/src/apc_trunk/apc_compile.c:390
#6  0x01958df6 in my_copy_zend_op (dst=0xa008146c, src=0xb7fbf1e0, 
ctxt=0xbfffb854)
    at /home/weltling/dws/src/apc_trunk/apc_compile.c:408
#7  0x0195ae4d in apc_copy_op_array (dst=0xa00811e8, src=0xb7fbebb8, 
ctxt=0xbfffb854)
    at /home/weltling/dws/src/apc_trunk/apc_compile.c:1299
#8  0x0195dccb in apc_compile_cache_entry (key=0xbfffceb4, h=0xbffff1dc, type=8, 
t=1343683222, op_array=0xbfffbe38, 
    cache_entry=0xbfffbe34) at /home/weltling/dws/src/apc_trunk/apc_main.c:439
#9  0x0195e592 in my_compile_file (h=0xbffff1dc, type=8) at 
/home/weltling/dws/src/apc_trunk/apc_main.c:603
#10 0x008cc3ac in zend_execute_scripts (type=8, retval=0x0, file_count=3)
    at /home/weltling/dws/src/php-5.4-nts/Zend/zend.c:1281
#11 0x0084018d in php_execute_script (primary_file=0xbffff1dc) at 
/home/weltling/dws/src/php-5.4-nts/main/main.c:2473
#12 0x009f3c2e in php_handler (r=0x82e3448) at /home/weltling/dws/src/php-5.4-
nts/sapi/apache2handler/sapi_apache2.c:667
#13 0x0807c3d7 in ap_run_handler (r=0x82e3448) at config.c:158
#14 0x0807cb08 in ap_invoke_handler (r=0x82e3448) at config.c:376
#15 0x0809bbd0 in ap_process_request (r=0x82e3448) at http_request.c:282
#16 0x08098bba in ap_process_http_connection (c=0x82df380) at http_core.c:190
#17 0x08084edf in ap_run_process_connection (c=0x82df380) at connection.c:43
#18 0x0808536b in ap_process_connection (c=0x82df380, csd=0x82df1e8) at 
connection.c:190
#19 0x080b5785 in child_main (child_num_arg=0) at prefork.c:667
#20 0x080b587e in make_child (s=0x80f0d18, slot=0) at prefork.c:712
#21 0x080b5e18 in ap_mpm_run (_pconf=0x80ec0a8, plog=0x812a1a0, s=0x80f0d18) at 
prefork.c:988
#22 0x08065662 in main (argc=2, argv=0xbffff674) at main.c:753
 [2012-07-31 17:58 UTC] ab@php.net
Automatic comment from SVN on behalf of ab
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=326908
Log: added basic traits implementation as reported in bug #62699
 [2012-07-31 18:00 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2012-07-31 18:00 UTC] ab@php.net
Could you please test the current trunk?
 [2012-08-01 08:25 UTC] franssen dot roland at gmail dot com
I've no experience in compiling PHP :( I need to do some homework first to run a 2nd PHP installation on my webserver. Currently I use the dotdeb (stable) packages.

Will these fixes be released anyway? e.g. 5.4.6?

PS: perhaps the bugtracker could use a "Fix version(s)" field... as it currently only shows affected version(s).
 [2012-08-01 09:26 UTC] ab@php.net
No, I meant the APC trunk, as this is an APC issue. Could you compile the APC 
trunk going the phpize way? Please look here 
http://de2.php.net/manual/en/install.pecl.phpize.php
 [2012-08-01 10:53 UTC] franssen dot roland at gmail dot com
Yes I can ;-) I'm not sure I did the right thing.. but actually somehthing happened.

$ svn checkout http://svn.php.net/repository/pecl/apc/trunk ~/php-apc-trunk
$ cd ~/php-apc-trunk
$ phpize
$ ./configure
$ make
$ mv /usr/lib/php5/<latest>yyyymmdd/apc.so apc-old.so
$ cp ~/php-apc-trunk/modules/apc.so /usr/lib/php5/<latest>yyyymmdd/apc.so
$ service apache2 restart

First page load gives the exepcted result after a page refresh the server crashes (Status Aborted).
 [2012-08-01 11:58 UTC] ab@php.net
Ah, then you could run gdb using the built-in cli server, like this

ZEND_DONT_UNLOAD_MODULES=1 USE_ZEND_ALLOC=0  gdb --args php -n -d 
extension_dir=/path -d extension=apc.so -d apc.enabled=1 -d apc.enable_cli=1 -d 
apc.stat=0 -d apc.cache_by_default=1 -S localhost:8964 snippet.php

Or with apache, read here https://bugs.php.net/bugs-generating-backtrace.php . 
Perhaps you have valgrind there, would be even better )
 [2012-08-01 12:00 UTC] ab@php.net
Automatic comment from SVN on behalf of ab
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=326923
Log: adding test for bug #62699
 [2012-08-01 14:29 UTC] franssen dot roland at gmail dot com
I'll need a little help. Running the snippet code via the built-in webserver gives the same result;

[Wed Aug  1 16:21:27 2012] 127.0.0.1:56309 [200]: /test_apc.php
Segmentation fault (core dumped)

Then the terminal crashes.

I'm stuck with gdb... (never heard of it ;-)). I understand it's a debugger tool and you probably need a backtrace... however I have no idea where it's located.

$ ZEND_DONT_UNLOAD_MODULES=1 USE_ZEND_ALLOC=0  gdb --args php -n -d 
extension_dir=/usr/lib/php5/<latest>yyyymmdd -d extension=apc.so -d apc.enabled=1 -d apc.enable_cli=1 -d 
apc.stat=0 -d apc.cache_by_default=1 -S localhost:8964 test_apc.php

GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /usr/bin/php...(no debugging symbols found)...done.

$ (gdb) bt
No stack
 [2012-08-01 15:03 UTC] ab@php.net
After you've seen

$ (gdb)

type "run", gdb will report about a segfault and give you the console back, then 
run bt. If it don't fail when you run - access 127.0.0.1:56309 with the browser, 
may be several times until it segfaults. That's should be
 [2012-08-01 15:16 UTC] franssen dot roland at gmail dot com
Ok. I think I did it.

roland@ubuntu:~$ cd public_html/
roland@ubuntu:~/public_html$ ZEND_DONT_UNLOAD=1 USE_ZEND_ALLOC=0 gdb --args php -n -d extension_dir=/usr/lib/php5/20100525 -d extension=apc.so -d apc.enabled=1 -d apc.enable_cli=1 -d apc.stat=0 -d apc.cache_by_default=1 -S localhost:8964 test_apc.php
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /usr/bin/php...(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/php -n -d extension_dir=/usr/lib/php5/20100525 -d extension=apc.so -d apc.enabled=1 -d apc.enable_cli=1 -d apc.stat=0 -d apc.cache_by_default=1 -S localhost:8964 test_apc.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
PHP 5.4.5-1~dotdeb.0 Development Server started at Wed Aug  1 17:12:23 2012
Listening on localhost:8964
Document root is /home/roland/public_html
Press Ctrl-C to quit.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff4aeb3e1 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ffff4aeb3e1 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ffff3c537ee in apc_pstrdup (s=0x4 <Address 0x4 out of bounds>, 
    pool=0x1021400) at /home/roland/php-apc-trunk/apc_pool.c:483
#2  0x00007ffff3c4efae in apc_copy_class_entry_for_execution (
    src=0x7ffff2045f60, ctxt=0x7fffffffa6d0)
    at /home/roland/php-apc-trunk/apc_compile.c:1951
#3  0x00007ffff3c4f54a in install_class (cl=..., ctxt=0x7fffffffa6d0, lazy=0)
    at /home/roland/php-apc-trunk/apc_main.c:165
#4  0x00007ffff3c506f4 in cached_compile (ctxt=0x7fffffffa6d0, 
    h=<optimized out>, type=<optimized out>)
    at /home/roland/php-apc-trunk/apc_main.c:345
#5  my_compile_file (h=0x7fffffffcb30, type=8)
    at /home/roland/php-apc-trunk/apc_main.c:541
#6  0x0000000000543101 in ?? ()
#7  0x00000000006c7d9a in zend_execute_scripts ()
#8  0x00000000007784b5 in ?? ()
#9  0x000000000077b3a8 in ?? ()
#10 0x000000000077b8de in ?? ()
#11 0x000000000077c24a in ?? ()
#12 0x00000000007744f8 in ?? ()
#13 0x00007ffff49ab76d in __libc_start_main ()
   from /lib/x86_64-linux-gnu/libc.so.6
#14 0x0000000000430159 in _start ()
 [2012-08-01 17:20 UTC] ab@php.net
Automatic comment from SVN on behalf of ab
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=326931
Log: fixed the empty trait alias case for bug #62699
 [2012-08-01 17:22 UTC] ab@php.net
Thanks, that was very useful. Could you please svn up and test again?

Btw. the snippet failing should be different from what you've posted in the 
description ;)
 [2012-08-08 16:11 UTC] ab@php.net
Automatic comment from SVN on behalf of ab
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=327028
Log: one more test for bug 62699
 [2012-08-09 20:40 UTC] ab@php.net
Automatic comment from SVN on behalf of ab
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=327033
Log: reworked and cleaned the stuff for bug #62699
tested on debian squeeze where a further implementation bug could be reproduced
 [2012-08-23 19:04 UTC] franssen dot roland at gmail dot com
Sorry for the late reaction (I was on vacation)...

It seems to be fixed as of 3.1.12 (packaged with php 5.4.6~dotdeb). Also tested the current trunk once more (3.1.13-dev) which is still OK.
 [2013-02-18 00:35 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 02:01:28 2024 UTC