Code Monkey home page Code Monkey logo

uopz's Introduction

UOPZ

User Operations for Zend

Build and Test Coverage Status

The uopz extension is focused on providing utilities to aid with unit testing PHP code.

It supports the following activities:

  • Intercepting function execution
  • Intercepting object creation
  • Hooking into function execution
  • Manipulation of function statics
  • Manipulation of function flags
  • Redefinition of constants
  • Deletion of constants
  • Runtime creation of functions and methods

Note: All of the above activities are compatible with opcache

Requirements and Installation

If you use XDebug you need to use version 2.9.4 or higher.

See INSTALL.md

API

The PHP API for uopz

/**
* Provide a return value for an existing function
* @param string class
* @param string function
* @param mixed value
* @param bool execute
* If value is a Closure and execute flag is set, the Closure will
* be executed in place of the existing function
**/
function uopz_set_return(string class, string function, mixed value [, bool execute = 0]) : bool;

/**
* Provide a return value for an existing function
* @param string function
* @param mixed value
* @param bool execute
* If value is a Closure and execute flag is set, the Closure will
* be executed in place of the existing function
**/
function uopz_set_return(string function, mixed value [, bool execute = 0]) : bool;

/**
* Get a previously set return value
* @param string class
* @param string function
**/
function uopz_get_return(string class, string function) : mixed;

/**
* Get a previously set return value
* @param string function
**/
function uopz_get_return(string function) : mixed;

/**
* Unset a previously set return value
* @param string class
* @param string function
**/
function uopz_unset_return(string class, string function) : bool;

/**
* Unset a previously set return value
* @param string function
**/
function uopz_unset_return(string function) : bool;

/**
* Use mock in place of class
* @param string class
* @param mixed mock
* Mock can be an object, or the name of a class
**/
function uopz_set_mock(string class, mixed mock);

/**
* Get previously set mock for class
* @param string class
**/
function uopz_get_mock(string class);

/**
* Unset previously set mock
* @param string class
**/
function uopz_unset_mock(string class);

/**
* Get static variables from method scope
* @param string class
* @param string function
**/
function uopz_get_static(string class, string function) : array;

/**
* Get static variables from function scope
* @param string function
**/
function uopz_get_static(string function) : array;

/**
* Set static variables in method scope
* @param string class
* @param string function
* @param array static
**/
function uopz_set_static(string class, string function, array static);

/**
* Set static variables in function scope
* @param string function
* @param array static
**/
function uopz_set_static(string function, array static);

/**
* Execute hook when entering class::function
* @param string class
* @param string function
**/
function uopz_set_hook(string class, string function, Closure hook) : bool;

/**
* Execute hook when entering function
* @param string function
**/
function uopz_set_hook(string function, Closure hook) : bool;

/**
* Get previously set hook on class::function
* @param string class
* @param string function
**/
function uopz_get_hook(string class, string function) : Closure;

/**
* Get previously set hook on function
* @param string function
**/
function uopz_get_hook(string function) : Closure;

/**
* Remove previously set hook on class::function
* @param string class
* @param string function
**/
function uopz_unset_hook(string class, string function) : bool;

/**
* Remove previously set hook on function
* @param string function
**/
function uopz_unset_hook(string function) : bool;

/**
* Add a non-existent method
* @param string class
* @param string function
* @param Closure handler
* @param int flags
* @param bool all
* If all is true, all classes that descend from class will also be affected
**/
function uopz_add_function(string class, string function, Closure handler [, int flags = ZEND_ACC_PUBLIC [, bool all = true]]) : bool;

/**
* Add a non-existent function
* @param string function
* @param Closure handler
* @param int flags
* @param bool all
* If all is true, all classes that descend from class will also be affected
**/
function uopz_add_function(string function, Closure handler [, int flags = ZEND_ACC_PUBLIC [, bool all = true]]) : bool;

/**
* Delete a previously added method
* @param string class
* @param string function
* @param bool all
* If all is true, all classes that descend from class will also be affected
**/
function uopz_del_function(string class, string function, [, bool all = true]);

/**
* Delete a previously added function
* @param string function
**/
function uopz_del_function(string function);

/**
* Redefine $class::$constant to $value
* @param string class
* @param string constant
* @param mixed  value
* Note: only user constants should be redefined
* Note: if the constant does not exist it will be created
**/
function uopz_redefine(string class, string constant, mixed value);

/**
* Redefine $constant to $value
* @param string constant
* @param mixed  value
* Note: only user constants should be redefined
* Note: if the constant does not exist it will be created
**/
function uopz_redefine(string constant, mixed value);

/**
* Delete $class::$constant
* @param string class
* @param string constant
* Note: only user constants should be undefined
**/
function uopz_undefine(string class, string constant);

/**
* Delete $constant
* @param string constant
* Note: only user constants should be undefined
**/
function uopz_undefine(string constant);

/**
 * Get or set flags on $class::$method()
 * @param string class
 * @param string method
 * @param int flags
 */
function uopz_flags(string class, string method [, int flags]) : int;

/**
 * Get or set flags on $method()
 * @param string method
 * @param int flags
 */
function uopz_flags(string function, [, int flags]) : int;

/**
* Set instance property
* @param object instance
* @param string property
* @param mixed value
*/
function uopz_set_property(object instance, string property, mixed value);

/**
* Set static class property
* @param string class
* @param string property
* @param mixed value
*/
function uopz_set_property(string class, string property, mixed value);

/**
* Get instance property
* @param object instance
* @param string property
*/
function uopz_get_property(object instance, string property) : mixed;

/**
* Get static class property
* @param string class
* @param string property
*/
function uopz_get_property(string class, string property) : mixed;

/**
* Retrieve the last set exit() status
* Note: opcache optimizes away dead code after unconditional exit
* Note: exit() breaks xdebug hooks
*/
function uopz_get_exit_status() : mixed;

/**
* Allows control over disabled exit opcode
* @param bool allow
* Note: by default exit will be ignored
*/
function uopz_allow_exit(bool allow) : void;

Supported Versions

The currently supported version of uopz is 7 which requires PHP8.0+

Testing

Running the test suite

After make has executed, run:

make test

You are done reading

That is all !!!

uopz's People

Contributors

bwoebi avatar cmb69 avatar dstogov avatar kornrunner avatar krakjoe avatar lyrixx avatar michaelmoussa avatar mingliangt avatar mszabo-wikia avatar nikic avatar petk avatar remicollet avatar rlerdorf avatar sannis avatar smillerdev avatar tony2001 avatar weltling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uopz's Issues

uopz+phpunit: Fatal error or seagfault when repeat run script with uopz_function() more than once

Hi Joe,

I've got "Fatal error: Cannot call overloaded function for non-object in UopzTest.php on line 10" when run this script https://gist.github.com/antonvolkov/86626df547bc4395d837 using command like "phpunit --repeat=10 UopzTest.php", valgrind log is below

==30651== Invalid read of size 8                                                                                                                             
==30651==    at 0x635F6F: ZEND_SEND_VAL_SPEC_CONST_HANDLER (zend_vm_execute.h:2499)                                                                          
==30651==    by 0x67B197: execute_ex (zend_vm_execute.h:363)                                                                                                 
==30651==    by 0x5EEFBB: zend_call_function (zend_execute_API.c:939)                                                                                        
==30651==    by 0x4D67B8: zim_reflection_method_invokeArgs (php_reflection.c:3015)                                                                           
==30651==    by 0x681288: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:550)                                                                           
==30651==    by 0x67B197: execute_ex (zend_vm_execute.h:363)                                                                                                 
==30651==    by 0x5FC251: zend_execute_scripts (zend.c:1449)                                                                                                 
==30651==    by 0x597548: php_execute_script (main.c:2573)                                                                                                   
==30651==    by 0x6B0214: do_cli (php_cli.c:994)                                                                                                             
==30651==    by 0x6B09D4: main (php_cli.c:1380)                                                                                                              
==30651==  Address 0xcdb82f0 is 48 bytes inside a block of size 248 free'd                                                                                   
==30651==    at 0x4C2970C: free (vg_replace_malloc.c:468)                                                                                                    
==30651==    by 0x61FC80: free (zend_signal.c:101)                                                                                                           
==30651==    by 0x60D518: zend_hash_del_key_or_index (zend_hash.c:535)                                                                                       
==30651==    by 0xD5751C2: zif_uopz_delete (uopz.c:1329)                                                                                                     
==30651==    by 0x681288: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:550)                                                                           
==30651==    by 0x67B197: execute_ex (zend_vm_execute.h:363)                                                                                                 
==30651==    by 0x5EEFBB: zend_call_function (zend_execute_API.c:939)                                                                                        
==30651==    by 0x4D67B8: zim_reflection_method_invokeArgs (php_reflection.c:3015)                                                                           
==30651==    by 0x681288: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:550)                                                                           
==30651==    by 0x67B197: execute_ex (zend_vm_execute.h:363)                                                                                                 
==30651==    by 0x5FC251: zend_execute_scripts (zend.c:1449)                                                                                                 
==30651==    by 0x597548: php_execute_script (main.c:2573)                                                                                                   
==30651==    by 0x6B0214: do_cli (php_cli.c:994)                                                                                                             
==30651==    by 0x6B09D4: main (php_cli.c:1380)

I've got "seagfault (core dumped)" when run this script https://gist.github.com/antonvolkov/b1ac2e4faad546d7278d with the same command "phpunit --repeat=10 UopzTest2.php"

By the way could you please clarify are you planning to make Uopz works with php7?

Thank you in advance

Support of magic methods redefining?

It would be nice to have ability to redefine magic methods.
Currently there is error message "will not override magic methods, too magical" occurs when trying to redefine one.

Are you going to implement this feature in future?
Or there are some critical impediments?

Problem with typehinted callable passed to uopz_add_function

Hello,

The following code:

class	dbClass {}

class	testClass
{
	static private function	db() : dbClass
	{
		return new dbClass();
	}
}

uopz_add_function(testClass::class, 'phpunit_db', static function() : dbClass { return self::db(); }, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC);
$db = testClass::phpunit_db();

produces the following error:

PHP Fatal error: Uncaught TypeError: Return value of testClass::{closure}() must be an instance of , instance of dbClass returned in ...

Environment:

$ php -v
PHP 7.1.3 (cli) (built: Apr 11 2017 13:08:01) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Xdebug v2.5.1, Copyright (c) 2002-2017, by Derick Rethans
with Zend OPcache v7.1.3, Copyright (c) 1999-2017, by Zend Technologies

Array constant

Hello,

uopz_redefine() refuses to redefine a constant as array.

class	testClass
{
	const	ARR = [ 1, 2, 3 ];
}

uopz_redefine(testClass::class, 'ARR', [ 1, 2, 4 ]);

Results in:

PHP Fatal error: Uncaught RuntimeException: failed to redefine the constant testClass::ARR, type not allowed

Using master, following PHP environment:

$ php -v
PHP 7.1.3 (cli) (built: Apr 11 2017 13:08:01) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Xdebug v2.5.1, Copyright (c) 2002-2017, by Derick Rethans
with Zend OPcache v7.1.3, Copyright (c) 1999-2017, by Zend Technologies

Extends for final class, return of arbitrary class instance.

I am experimenting a little bit with uopz extension as weaving engine for implementation of aspect oriented paradigm in PHP by using proxies.

This seams perfect fit, in general it is possible to do it with "set mock" end "extends" functions, and it seams that it is possible to do it without modifying original source code.

However, two functionalities are missing

  1. Possibility to remove "final" modifier from class in order to extend it in runtime, it would help generating proxies without modifying original source code.
  2. In order to support "initialization" interception, it is required to have possibility to return arbitrary class instance for "new" keyword. This was possible in uopz for PHP v < 7, it is not possible now.

Stated 1. and 2. can be achieved as in GoAOP - by modifying original source code. However, it would be awesome if it could be supported by uopz, in that matter, AOP implementation in userland could be implemented much, much easier, and as it seams from initial experiments, it would be much more performant.

So, since I am not C developer and I don't have a knowledge about PHP internals, I was wondering if 1 and/or 2 are possible and if there are plans to implement those in future?

Thanks!

exit code corruption

Noticed running "phpunit" on Horde_Service_Weather library.

 + phpunit --include-path=/builddir/build/BUILD/php-horde-Horde-Service-Weather-2.1.0/Horde_Service_Weather-2.1.0/lib -d date.timezone=UTC .
 PHPUnit 3.7.32 by Sebastian Bergmann.
 Configuration read from /builddir/build/BUILD/php-horde-Horde-Service-Weather-2.1.0/Horde_Service_Weather-2.1.0/test/Horde/Service/Weather/phpunit.xml
 FF....
 Time: 34 ms, Memory: 5.75Mb
 There were 2 failures:
 1) Horde_Service_Weather_WundergroundTest::testCurrentConditions
 Failed asserting that two strings are equal.
 --- Expected
 +++ Actual
 @@ @@
 -'2011-11-27 23:10:25'
 +'2011-11-28 04:10:25'
 /builddir/build/BUILD/php-horde-Horde-Service-Weather-2.1.0/Horde_Service_Weather-2.1.0/test/Horde/Service/Weather/WundergroundTest.php:51
 2) Horde_Service_Weather_WundergroundTest::testGetStation
 Failed asserting that two strings are equal.
 --- Expected
 +++ Actual
 @@ @@
 -'2011-11-27 06:48:00'
 +'2011-11-28 06:48:00'
 /builddir/build/BUILD/php-horde-Horde-Service-Weather-2.1.0/Horde_Service_Weather-2.1.0/test/Horde/Service/Weather/WundergroundTest.php:60
 FAILURES!
 Tests: 6, Assertions: 78, Failures: 2.
 + exit 0

PHP exit code should not 0
Without uopz, exit code is correct (reports failure)

Reproduced with php 5.4, 5.5 and 5.6, with uopz 2.0.2 and 2.0.3

Trivial test return 2 as expected.

 $ php -r 'exit(2);' ; echo $?
 2

Allow returning an arbitrary object from the mocked "new" call

Feature request:

  • allow ZEND_NEW to be overloaded in such a way that it returns an arbitrary object coming from the overload callback (call to constructor is skipped unconditionally in such case)

I'd be happy to hear back if that feature fits the general roadmap of uopz.

Background story:

Wikia currently uses PHP 5.4 and with help of runkit + modified version of php-test-helpers (Wikia/php-test-helpers@9a28725) we were able to have a robust testing environment that satisfies our needs in the area of testing MediaWiki-derived code base.
As we're transitioning to PHP 5.6 we found out that uopz gives us all the functionality of the previous tandem in a single extension except the feature described above. We'd be very happy if we could get the missing piece implemented.

module can not be loaded on Windows Bitnami WAMP stack

I already tried to put zend_extension=php_uopz.dll before opcache and restarted the server but it always says Failed loading C:/Bitnami/wampstack-5.6.16-0/php/ext\php_uopz.dll but the file is there.

I tried php_uopz-2.0.7-5.6-nts-vc11-x64 and php_uopz-2.0.7-5.6-ts-vc11-x64 but still get the same error.

Is there something else we have to configure or change before this works? Any other requirements? Did someone else get it working under Windows?

Impossible to catch a exception thrown by uopz_set_return

class A {
   function test() {
      echo 123;
      return 321;
    }
}
uopz_set_return('A', 'test', function () {
  throw new \Exception('set return');
}, true);

$a = new A();
try {
   echo $a->test() . PHP_EOL;
} catch (\Exception $e) {
  var_dump($e->getMessage()); // never be called
}

PHP Fatal error: Uncaught Exception

uopz breaks when xdebug is loaded

Hey @krakjoe awesome extension, excited to start using it!

Currently it seems like xdebug breaks uopz when both are loaded (and load order doesn't matter) I didn't try a lot of stuff but the following exits with no output. (From the README)

<?php
uopz_overload(ZEND_EXIT, function($status = 0){});

class Test {
    public function method() {
        exit();
    }
}

class Unit {
    public function test() {
        $test = new Test();
        $test->method();

        return true;
    }
}
$unit = new Unit();
var_dump($unit->test());
uopz_overload(ZEND_EXIT, null);
var_dump($unit->test());
echo "failed";
?>

Is it possible to have two extensions in this area? (so I could submit a PR to xdebug/uopz) or do you know if the Zend VM was designed to only have one at a time.

thanks

Segmentation fault (uopz_set_return)

When I ran following script with uopz( 7156777 ), I faced Segmentation fault.

vagrant@vagrant:~$ cat test.php
<?php

function f1(){}
function f2(){}

uopz_set_return('f1','f2', 1);
uopz_unset_return('f1');
uopz_set_return('f1','f2', 1);

echo 'Done';

vagrant@vagrant:~$ php -d extension=uopz/modules/uopz.so test.php
Segmentation fault (core dumped)

vagrant@vagrant:~$ gdb php --core core
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
Copyright (C) 2016 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".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from php...(no debugging symbols found)...done.

warning: core file may not match specified executable file.
[New LWP 14819]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `php -d extension=uopz/modules/uopz.so test.php'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000055c81fbc4ba5 in instanceof_function ()
(gdb) bt
#0  0x000055c81fbc4ba5 in instanceof_function ()
#1  0x00007f16e8728882 in zif_uopz_set_return (execute_data=0x7f16ed8130c0, return_value=0x7f16ed813090) at /home/vagrant/uopz/uopz.c:151
#2  0x000055c81fbbdc9a in dtrace_execute_internal ()
#3  0x000055c81fc52940 in ?? ()
#4  0x000055c81fc0df8b in execute_ex ()
#5  0x000055c81fbbdb31 in dtrace_execute_ex ()
#6  0x000055c81fc61d57 in zend_execute ()
#7  0x000055c81fbcdd33 in zend_execute_scripts ()
#8  0x000055c81fb6e5a0 in php_execute_script ()
#9  0x000055c81fc63a17 in ?? ()
#10 0x000055c81fa530a4 in main ()

vagrant@vagrant:~$ php -v
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies

Mocking new does not work properly in a few cases

The cases which appear not to be handled by uopz (php7):

  • new $variable
  • use Ns\X as Y; new Y;
  • uopz_set_mock('\\Ns\\X',....);

The issues are showcased in the code below:

a.php

<?php

class Foo {}
class Bar {}

$foo = 'Foo';
uopz_set_mock('Foo', 'Bar');

echo get_class(new Foo) . PHP_EOL;  // prints: Bar
echo get_class(new Bar) . PHP_EOL;  // prints: Bar
echo get_class(new $foo) . PHP_EOL; // prints: Foo - incorrect!

ns.php

<?php

namespace SomeNamespace {
    class NsFoo {}
    class NsBar {}
    class NsFoo2 {}
    class NsBar2 {}

    uopz_set_mock('SomeNamespace\\NsFoo', 'SomeNamespace\NsBar');
    uopz_set_mock('\\SomeNamespace\\NsFoo2', '\\SomeNamespace\\NsBar2');

    $nsfoo1 = 'SomeNamespace\\NsFoo';
    $nsfoo2 = '\\SomeNamespace\\NsFoo2';
    echo get_class(new NsFoo) . PHP_EOL;   // prints: SomeNamespace\NsBar
    echo get_class(new NsBar) . PHP_EOL;   // prints: SomeNamespace\NsBar
    echo get_class(new $nsfoo1) . PHP_EOL; // prints: SomeNamespace\NsFoo - incorrect!
    echo get_class(new $nsfoo2) . PHP_EOL; // printf: SomeNamespace\NsFoo2 - incorrect!
}

b.php

<?php

include "ns.php";

use SomeNamespace\NsFoo2 as Foox2;

echo '--- from b.php ---' . PHP_EOL;
echo get_class(new SomeNamespace\NsFoo) . PHP_EOL;  // prints: SomeNamespace\NsBar
echo get_class(new \SomeNamespace\NsFoo) . PHP_EOL; // prints: SomeNamespace\NsBar
echo get_class(new Foox2) . PHP_EOL;                // prints: SomeNamespace\NsFoo2 - incorrect!
echo get_class(new $nsfoo1) . PHP_EOL;              // prints: SomeNamespace\NsFoo - incorrect!
echo get_class(new $nsfoo2) . PHP_EOL;              // prints: SomeNamespace\NsFoo2 - incorrect!

Environment details:

wladek@dev-php7:~/tmp$ php -v
PHP 7.0.2-4+deb.sury.org~trusty+1 (cli) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.4.0RC4, Copyright (c) 2002-2016, by Derick Rethans
uopz
uopz support => enabled
Version => 5.0.2-dev

I'd bet all of the constructor calls should return an object of one of the Bar classes but that's not the case as shown in the code even though I actually requested uopz to mock all the Foo classes.

Is it something that could be fixed?

exception from ZEND_EXIT overload

with older versions of uopz I used to be able to raise an exception from a ZEND_EXIT overload, which I would catch/expect in PHPUnit.
the latest changes seem to make this impossible, since I now have to return something from the overload function in order to continue execution.
is this change supposed to break behaviour? can I still throw exceptions in the overload somehow or do I have to refactor my testsuite?

Segmentation fault

Test case:

class Test {
    public $s = 'def';

    public function __construct($x) {
        $this->s = $x;
    }
}

uopz_function(Test::class, '__construct', function(){$this->s = 'redefined';});
var_dump((new Test('vvv')));

uopz_restore(Test::class, '__construct');
var_dump((new Test('vvv')));
$ php ~/1.php
/home/axp/1.php:12:
class Test#1 (1) {
  public $s =>
  string(9) "redefined"
}
Segmentation fault (core dumped)

php version:

$ php -v
PHP 7.0.5 (cli) (built: Mar 29 2016 18:07:10) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

php -i
strace

workaround is to use uopz_copy instead of restore:

$backup = uopz_copy(Test::class, '__construct');
uopz_function(Test::class, '__construct', function(){$this->s = 'redefined';});
var_dump((new Test('vvv')));

uopz_function(Test::class, '__construct', $backup);
var_dump((new Test('vvv')));

Compile guide?

Want a PR for a compile guide?

pretty much (at least on xenial)

git clone https://github.com/krakjoe/uopz
cd uopz
phpize
./configure
make
make test
sudo make install
sudo cat > /etc/php/7.0/mods-available/uopz.ini <<EOF
; configuration for php uopz module
; priority=5
extension=uopz.so
EOF

Some ZEND_ACC_* constants have been removed in 5.0.0

The constants ZEND_ACC_CLASS, ZEND_ACC_INTERFACE and ZEND_ACC_TRAIT seem to have been removed in uopz 5.0.0, even though they appear to be still useful for uopz_flags($class, null, …) (at least 0 can be passed as $flags to "un-final-ize" a class in uopz 5.0.2). If these constants won't be re-introduced, I can fix the PHP manual accordingly.

Furthermore, obviously ZEND_ACC_FETCH has also been removed as of uopz 5.0.0. However, the constant is still mentioned in the README, what is rather confusing, particularly, as the $flags parameter of uopz_flags() apparently is now optional.

uopz breaks zend.assertions setting

Test script:

<?php
$testvar="a";
assert(is_bool($testvar), 'foo');
print "this is a test\n";

Without uopz

$ php -n -d zend.assertions=-1 foo.php 
this is a test

With uopz

$ php -n -d extension=uopz.so -d zend.assertions=-1 foo.php 
Warning: assert(): foo failed in /tmp/foo.php on line 5
this is a test

uopz breaks user-level session storage

Call to php_uopz_clean_user_function and php_uopz_clean_user_class in PHP_RSHUTDOWN_FUNCTION (uopz.c:690-691) removes all user-defined functions, including user-defined session storage handlers which may still be needed later in RSHUTDOWN for PHP's session module in order to write session data and close the session properly.

This results in bogus PHP Warning: "Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0" and breaks user-level session storage when uopz module is enabled.

Unable to overload exit in PHP 5.5.14 and PHP 5.4.30

Test Script:

<?php

if (function_exists('uopz_overload')) {
    if (ini_get('uopz.overloads')) {
        echo "overloading exit()\n";
        uopz_overload(ZEND_EXIT, function(){});
    }
}
exit();

echo "This does not get output despite exit being overloaded.\n";

Output:

% php overload.php 
overloading exit()

Despite uopz being installed and overloads being enabled in php.ini, it simply doesn't work.

PHP Version:

% php --version
PHP 5.5.14 (cli) (built: Jul 22 2014 22:24:54) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

Note I have disabled the opcache zend extension.
Same results happens for php54:

% php --version            
PHP 5.4.30 (cli) (built: Jul 22 2014 21:34:41) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

Do you have any pointers how to debug or fix this?

Some tests failed on Xubuntu 15.04 and PHP 5.6.4

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Test exit overload [tests/001.phpt]
Test new overload [tests/002.phpt]
Test add trait [tests/003.phpt]
Test fetch class overload [tests/034.phpt]
Test fetch class and compose [tests/035.phpt]
Test exit overload with parameters [tests/050.phpt]
=====================================================================


=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :    0
Exts tested     :   52
---------------------------------------------------------------------

Number of tests :   49                49
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    6 ( 12.2%) ( 12.2%)
Expected fail   :    0 (  0.0%) (  0.0%)
Tests passed    :   43 ( 87.8%) ( 87.8%)
---------------------------------------------------------------------
Time taken      :    2 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Test exit overload [tests/001.phpt]
Test new overload [tests/002.phpt]
Test add trait [tests/003.phpt]
Test fetch class overload [tests/034.phpt]
Test fetch class and compose [tests/035.phpt]
Test exit overload with parameters [tests/050.phpt]
=====================================================================


================================================================================
/home/jean/dev/www/<mycompany>/QA/resources/uopz/tests/001.phpt
================================================================================

================================================================================
001+ 
001- bool(true)
================================================================================



================================================================================
/home/jean/dev/www/<mycompany>/QA/resources/uopz/tests/002.phpt
================================================================================
bool(false)
bool(true)
================================================================================
001+ bool(false)
002- bool(true)
================================================================================



================================================================================
/home/jean/dev/www/<mycompany>/QA/resources/uopz/tests/003.phpt
================================================================================
bool(false)
================================================================================
001+ bool(false)
001- bool(true)
================================================================================



================================================================================
/home/jean/dev/www/<mycompany>/QA/resources/uopz/tests/034.phpt
================================================================================
Fatal error: Class 'other' not found in /home/jean/dev/www/<mycompany>/QA/resources/uopz/tests/034.php on line 9
================================================================================
001+ Fatal error: Class 'other' not found in /home/jean/dev/www/<mycompany>/QA/resources/uopz/tests/034.php on line 9
001- object(test)#%d (%d) {
002- }
003- array(1) {
004-   ["mine"]=>
005-   string(4) "mine"
006- }
================================================================================



================================================================================
/home/jean/dev/www/<mycompany>/QA/resources/uopz/tests/035.phpt
================================================================================
Fatal error: Class 'test' not found in /home/jean/dev/www/<mycompany>/QA/resources/uopz/tests/035.php on line 26
================================================================================
001+ Fatal error: Class 'test' not found in /home/jean/dev/www/<mycompany>/QA/resources/uopz/tests/035.php on line 26
001- object(test)#%d (%d) {
002-   ["arg":protected]=>
003-   object(stdClass)#%d (0) {
004-   }
005- }
006- array(1) {
007-   ["TestBundle"]=>
008-   string(10) "TestBundle"
009- }
================================================================================



================================================================================
/home/jean/dev/www/<mycompany>/QA/resources/uopz/tests/050.phpt
================================================================================

================================================================================
001+ 
001- int(42)
002- Hello World
003- int(84)
================================================================================




================================================================================
BUILD ENVIRONMENT
================================================================================
OS:
Linux - Linux jean-Lenovo-G580 3.19.0-28-generic #30-Ubuntu SMP Mon Aug 31 15:52:51 UTC 2015 x86_64

Autoconf:
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.

Bundled Libtool:
libtool (GNU libtool) 2.4.2
Written by Gordon Matzigkeit <[email protected]>, 1996

Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

System Libtool:
N/A
Compiler:
N/A
Bison:
bison (GNU Bison) 3.0.2
Écrit par Robert Corbett et Richard Stallman.

Copyright © 2013 Free Software Foundation, Inc.
Ce logiciel est libre; voir les sources pour les conditions de
reproduction. AUCUNE garantie n'est donnée; tant pour des raisons
COMMERCIALES que pour RÉPONDRE À UN BESOIN PARTICULIER.

Libraries:
    linux-vdso.so.1 =>  (0x00007ffedc75e000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fd9320be000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fd931ea2000)
    libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007fd931abe000)
    libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007fd93185d000)
    libdb-5.3.so => /usr/lib/x86_64-linux-gnu/libdb-5.3.so (0x00007fd9314af000)
    libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007fd93129f000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fd931032000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd930d2a000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd930b26000)
    libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007fd93075d000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd930393000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd930175000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fd9322d9000)
    libicuuc.so.52 => /usr/lib/x86_64-linux-gnu/libicuuc.so.52 (0x00007fd92fdf7000)
    libicudata.so.52 => /usr/lib/x86_64-linux-gnu/libicudata.so.52 (0x00007fd92e58a000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd92e27b000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd92e065000)

PHPINFO

phpinfo()
PHP Version => 5.6.4-4ubuntu6.2

System => Linux jean-Lenovo-G580 3.19.0-28-generic #30-Ubuntu SMP Mon Aug 31 15:52:51 UTC 2015 x86_64
Build Date => Jul  2 2015 15:26:16
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
Scan this dir for additional .ini files => /etc/php5/cli/conf.d
Additional .ini files parsed => /etc/php5/cli/conf.d/04-uopz.ini,
/etc/php5/cli/conf.d/05-opcache.ini,
/etc/php5/cli/conf.d/10-pdo.ini,
/etc/php5/cli/conf.d/20-gd.ini,
/etc/php5/cli/conf.d/20-json.ini,
/etc/php5/cli/conf.d/20-mysql.ini,
/etc/php5/cli/conf.d/20-mysqli.ini,
/etc/php5/cli/conf.d/20-pdo_mysql.ini,
/etc/php5/cli/conf.d/20-readline.ini,
/etc/php5/cli/conf.d/20-xdebug.ini

PHP API => 20131106
PHP Extension => 20131226
Zend Extension => 220131226
Zend Extension Build => API220131226,NTS
PHP Extension Build => API20131226,NTS
Debug Build => no
Thread Safety => disabled
Zend Signal Handling => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => provided by mbstring
IPv6 Support => enabled
DTrace Support => enabled

Registered PHP Streams => https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, sslv3, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filters => zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk

This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
    with uopz v2.1.0, Copyright (c) 2014, by Joe Watkins <[email protected]>
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.6, Copyright (c) 2002-2014, by Derick Rethans


 _______________________________________________________________________


Configuration

bcmath

BCMath support => enabled

Directive => Local Value => Master Value
bcmath.scale => 0 => 0

bz2

BZip2 Support => Enabled
Stream Wrapper support => compress.bzip2://
Stream Filter support => bzip2.decompress, bzip2.compress
BZip2 Version => 1.0.6, 6-Sept-2010

calendar

Calendar support => enabled

Core

PHP Version => 5.6.4-4ubuntu6.2

Directive => Local Value => Master Value
allow_url_fopen => On => On
allow_url_include => Off => Off
always_populate_raw_post_data => 0 => 0
arg_separator.input => & => &
arg_separator.output => & => &
asp_tags => Off => Off
auto_append_file => no value => no value
auto_globals_jit => On => On
auto_prepend_file => no value => no value
browscap => no value => no value
default_charset => UTF-8 => UTF-8
default_mimetype => text/html => text/html
disable_classes => no value => no value
disable_functions => no value => no value
display_errors => STDERR => STDERR
display_startup_errors => Off => Off
doc_root => no value => no value
docref_ext => no value => no value
docref_root => no value => no value
enable_dl => Off => Off
enable_post_data_reading => On => On
error_append_string => no value => no value
error_log => no value => no value
error_prepend_string => no value => no value
error_reporting => 22527 => 22527
exit_on_timeout => Off => Off
expose_php => On => On
extension_dir => /usr/lib/php5/20131226 => /usr/lib/php5/20131226
file_uploads => On => On
highlight.comment => <font style="color: #FF8000">#FF8000</font> => <font style="color: #FF8000">#FF8000</font>
highlight.default => <font style="color: #0000BB">#0000BB</font> => <font style="color: #0000BB">#0000BB</font>
highlight.html => <font style="color: #000000">#000000</font> => <font style="color: #000000">#000000</font>
highlight.keyword => <font style="color: #007700">#007700</font> => <font style="color: #007700">#007700</font>
highlight.string => <font style="color: #DD0000">#DD0000</font> => <font style="color: #DD0000">#DD0000</font>
html_errors => Off => Off
ignore_repeated_errors => Off => Off
ignore_repeated_source => Off => Off
ignore_user_abort => Off => Off
implicit_flush => On => On
include_path => .:/usr/share/php:/usr/share/pear => .:/usr/share/php:/usr/share/pear
input_encoding => no value => no value
internal_encoding => no value => no value
log_errors => On => On
log_errors_max_len => 1024 => 1024
mail.add_x_header => On => On
mail.force_extra_parameters => no value => no value
mail.log => no value => no value
max_execution_time => 0 => 0
max_file_uploads => 20 => 20
max_input_nesting_level => 64 => 64
max_input_time => -1 => -1
max_input_vars => 1000 => 1000
memory_limit => -1 => -1
open_basedir => no value => no value
output_buffering => 0 => 0
output_encoding => no value => no value
output_handler => no value => no value
post_max_size => 8M => 8M
precision => 14 => 14
realpath_cache_size => 16K => 16K
realpath_cache_ttl => 120 => 120
register_argc_argv => On => On
report_memleaks => On => On
report_zend_debug => Off => Off
request_order => GP => GP
sendmail_from => no value => no value
sendmail_path => /usr/sbin/sendmail -t -i  => /usr/sbin/sendmail -t -i 
serialize_precision => 17 => 17
short_open_tag => Off => Off
SMTP => localhost => localhost
smtp_port => 25 => 25
sql.safe_mode => Off => Off
sys_temp_dir => no value => no value
track_errors => Off => Off
unserialize_callback_func => no value => no value
upload_max_filesize => 2M => 2M
upload_tmp_dir => no value => no value
user_dir => no value => no value
user_ini.cache_ttl => 300 => 300
user_ini.filename => .user.ini => .user.ini
variables_order => GPCS => GPCS
xmlrpc_error_number => 0 => 0
xmlrpc_errors => Off => Off
zend.detect_unicode => On => On
zend.enable_gc => On => On
zend.multibyte => Off => Off
zend.script_encoding => no value => no value

ctype

ctype functions => enabled

date

date/time support => enabled
"Olson" Timezone Database Version => 0.system
Timezone Database => internal
Default timezone => Europe/Berlin

Directive => Local Value => Master Value
date.default_latitude => 31.7667 => 31.7667
date.default_longitude => 35.2333 => 35.2333
date.sunrise_zenith => 90.583333 => 90.583333
date.sunset_zenith => 90.583333 => 90.583333
date.timezone => no value => no value

dba

DBA support => enabled
libdb header version => Berkeley DB 5.3.28: (September  9, 2013)
libdb library version => Berkeley DB 5.3.28: (September  9, 2013)
Supported handlers => cdb cdb_make db4 inifile flatfile 

Directive => Local Value => Master Value
dba.default_handler => flatfile => flatfile

dom

DOM/XML => enabled
DOM/XML API Version => 20031129
libxml Version => 2.9.2
HTML Support => enabled
XPath Support => enabled
XPointer Support => enabled
Schema Support => enabled
RelaxNG Support => enabled

ereg

Regex Library => Bundled library enabled

exif

EXIF Support => enabled
EXIF Version => 1.4 $Id: ab2a50435139d06a6aaac1b47adb458267625069 $
Supported EXIF Version => 0220
Supported filetypes => JPEG,TIFF

Directive => Local Value => Master Value
exif.decode_jis_intel => JIS => JIS
exif.decode_jis_motorola => JIS => JIS
exif.decode_unicode_intel => UCS-2LE => UCS-2LE
exif.decode_unicode_motorola => UCS-2BE => UCS-2BE
exif.encode_jis => no value => no value
exif.encode_unicode => ISO-8859-15 => ISO-8859-15

fileinfo

fileinfo support => enabled
version => 1.0.5
libmagic => 517

filter

Input Validation and Filtering => enabled
Revision => $Id: a408ee30dc87767f918de9439364deec6760290c $

Directive => Local Value => Master Value
filter.default => unsafe_raw => unsafe_raw
filter.default_flags => no value => no value

ftp

FTP support => enabled

gd

GD Support => enabled
GD Version => 2.1.1-dev
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.5.2
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 8
PNG Support => enabled
libPNG Version => 1.2.51
WBMP Support => enabled
XPM Support => enabled
libXpm Version => 30411
XBM Support => enabled
WebP Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 0 => 0

gettext

GetText Support => enabled

hash

hash support => enabled
Hashing Engines => md2 md4 md5 sha1 sha224 sha256 sha384 sha512 ripemd128 ripemd160 ripemd256 ripemd320 whirlpool tiger128,3 tiger160,3 tiger192,3 tiger128,4 tiger160,4 tiger192,4 snefru snefru256 gost gost-crypto adler32 crc32 crc32b fnv132 fnv1a32 fnv164 fnv1a64 joaat haval128,3 haval160,3 haval192,3 haval224,3 haval256,3 haval128,4 haval160,4 haval192,4 haval224,4 haval256,4 haval128,5 haval160,5 haval192,5 haval224,5 haval256,5 

iconv

iconv support => enabled
iconv implementation => glibc
iconv library version => 2.21

Directive => Local Value => Master Value
iconv.input_encoding => no value => no value
iconv.internal_encoding => no value => no value
iconv.output_encoding => no value => no value

json

json support => enabled
json version => 1.3.6
JSON-C headers version => 0.11.99
JSON-C library version => 0.11.99

libxml

libXML support => active
libXML Compiled Version => 2.9.2
libXML Loaded Version => 20902
libXML streams => enabled

mbstring

Multibyte Support => enabled
Multibyte string engine => libmbfl
HTTP input encoding translation => disabled
libmbfl version => 1.3.2

mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1.

Multibyte (japanese) regex support => enabled
Multibyte regex (oniguruma) backtrack check => On
Multibyte regex (oniguruma) version => 5.9.5

Directive => Local Value => Master Value
mbstring.detect_order => no value => no value
mbstring.encoding_translation => Off => Off
mbstring.func_overload => 0 => 0
mbstring.http_input => no value => no value
mbstring.http_output => no value => no value
mbstring.http_output_conv_mimetypes => ^(text/|application/xhtml\+xml) => ^(text/|application/xhtml\+xml)
mbstring.internal_encoding => no value => no value
mbstring.language => neutral => neutral
mbstring.strict_detection => Off => Off
mbstring.substitute_character => no value => no value

mhash

MHASH support => Enabled
MHASH API Version => Emulated Support

mysql

MySQL Support => enabled
Active Persistent Links => 0
Active Links => 0
Client API version => 5.6.25
MYSQL_MODULE_TYPE => external
MYSQL_SOCKET => /var/run/mysqld/mysqld.sock
MYSQL_INCLUDE => -I/usr/include/mysql
MYSQL_LIBS => -L/usr/lib/x86_64-linux-gnu -lmysqlclient_r 

Directive => Local Value => Master Value
mysql.allow_local_infile => On => On
mysql.allow_persistent => On => On
mysql.connect_timeout => 60 => 60
mysql.default_host => no value => no value
mysql.default_password => no value => no value
mysql.default_port => no value => no value
mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
mysql.default_user => no value => no value
mysql.max_links => Unlimited => Unlimited
mysql.max_persistent => Unlimited => Unlimited
mysql.trace_mode => Off => Off

mysqli

MysqlI Support => enabled
Client API library version => 5.6.25
Active Persistent Links => 0
Inactive Persistent Links => 0
Active Links => 0
Client API header version => 5.6.24
MYSQLI_SOCKET => /var/run/mysqld/mysqld.sock

Directive => Local Value => Master Value
mysqli.allow_local_infile => On => On
mysqli.allow_persistent => On => On
mysqli.default_host => no value => no value
mysqli.default_port => 3306 => 3306
mysqli.default_pw => no value => no value
mysqli.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock
mysqli.default_user => no value => no value
mysqli.max_links => Unlimited => Unlimited
mysqli.max_persistent => Unlimited => Unlimited
mysqli.reconnect => Off => Off
mysqli.rollback_on_cached_plink => Off => Off

openssl

OpenSSL support => enabled
OpenSSL Library Version => OpenSSL 1.0.1f 6 Jan 2014
OpenSSL Header Version => OpenSSL 1.0.1f 6 Jan 2014

Directive => Local Value => Master Value
openssl.cafile => no value => no value
openssl.capath => no value => no value

pcntl

pcntl support => enabled

pcre

PCRE (Perl Compatible Regular Expressions) Support => enabled
PCRE Library Version => 8.35 2014-04-04

Directive => Local Value => Master Value
pcre.backtrack_limit => 1000000 => 1000000
pcre.recursion_limit => 100000 => 100000

PDO

PDO support => enabled
PDO drivers => mysql

pdo_mysql

PDO Driver for MySQL => enabled
Client API version => 5.6.25

Directive => Local Value => Master Value
pdo_mysql.default_socket => /var/run/mysqld/mysqld.sock => /var/run/mysqld/mysqld.sock

Phar

Phar: PHP Archive support => enabled
Phar EXT version => 2.0.2
Phar API version => 1.1.1
SVN revision => $Id: ac6bd272c417316cc97fd46ea4f8372dcf054406 $
Phar-based phar archives => enabled
Tar-based phar archives => enabled
ZIP-based phar archives => enabled
gzip compression => enabled
bzip2 compression => enabled
OpenSSL support => enabled


Phar based on pear/PHP_Archive, original concept by Davey Shafik.
Phar fully realized by Gregory Beaver and Marcus Boerger.
Portions of tar implementation Copyright (c) 2003-2009 Tim Kientzle.
Directive => Local Value => Master Value
phar.cache_list => no value => no value
phar.readonly => On => On
phar.require_hash => On => On

posix

Revision => $Id: 1dfa9997ed76804e53c91e0ce862f3707617b6ed $

readline

Readline Support => enabled
Readline library => EditLine wrapper

Directive => Local Value => Master Value
cli.pager => no value => no value
cli.prompt => \b \>  => \b \> 

Reflection

Reflection => enabled
Version => $Id: b2a30058688ac580cb2883c4283c19fd0e00d535 $

session

Session Support => enabled
Registered save handlers => files user 
Registered serializer handlers => php_serialize php php_binary wddx 

Directive => Local Value => Master Value
session.auto_start => Off => Off
session.cache_expire => 180 => 180
session.cache_limiter => nocache => nocache
session.cookie_domain => no value => no value
session.cookie_httponly => Off => Off
session.cookie_lifetime => 0 => 0
session.cookie_path => / => /
session.cookie_secure => Off => Off
session.entropy_file => /dev/urandom => /dev/urandom
session.entropy_length => 32 => 32
session.gc_divisor => 1000 => 1000
session.gc_maxlifetime => 1440 => 1440
session.gc_probability => 0 => 0
session.hash_bits_per_character => 5 => 5
session.hash_function => 0 => 0
session.name => PHPSESSID => PHPSESSID
session.referer_check => no value => no value
session.save_handler => files => files
session.save_path => /var/lib/php5/sessions => /var/lib/php5/sessions
session.serialize_handler => php => php
session.upload_progress.cleanup => On => On
session.upload_progress.enabled => On => On
session.upload_progress.freq => 1% => 1%
session.upload_progress.min_freq => 1 => 1
session.upload_progress.name => PHP_SESSION_UPLOAD_PROGRESS => PHP_SESSION_UPLOAD_PROGRESS
session.upload_progress.prefix => upload_progress_ => upload_progress_
session.use_cookies => On => On
session.use_only_cookies => On => On
session.use_strict_mode => Off => Off
session.use_trans_sid => 0 => 0

shmop

shmop support => enabled

SimpleXML

Simplexml support => enabled
Revision => $Id: a915862ec47f9589309acc4996ca8f6179788746 $
Schema support => enabled

soap

Soap Client => enabled
Soap Server => enabled

Directive => Local Value => Master Value
soap.wsdl_cache => 1 => 1
soap.wsdl_cache_dir => /tmp => /tmp
soap.wsdl_cache_enabled => 1 => 1
soap.wsdl_cache_limit => 5 => 5
soap.wsdl_cache_ttl => 86400 => 86400

sockets

Sockets Support => enabled

SPL

SPL support => enabled
Interfaces => Countable, OuterIterator, RecursiveIterator, SeekableIterator, SplObserver, SplSubject
Classes => AppendIterator, ArrayIterator, ArrayObject, BadFunctionCallException, BadMethodCallException, CachingIterator, CallbackFilterIterator, DirectoryIterator, DomainException, EmptyIterator, FilesystemIterator, FilterIterator, GlobIterator, InfiniteIterator, InvalidArgumentException, IteratorIterator, LengthException, LimitIterator, LogicException, MultipleIterator, NoRewindIterator, OutOfBoundsException, OutOfRangeException, OverflowException, ParentIterator, RangeException, RecursiveArrayIterator, RecursiveCachingIterator, RecursiveCallbackFilterIterator, RecursiveDirectoryIterator, RecursiveFilterIterator, RecursiveIteratorIterator, RecursiveRegexIterator, RecursiveTreeIterator, RegexIterator, RuntimeException, SplDoublyLinkedList, SplFileInfo, SplFileObject, SplFixedArray, SplHeap, SplMinHeap, SplMaxHeap, SplObjectStorage, SplPriorityQueue, SplQueue, SplStack, SplTempFileObject, UnderflowException, UnexpectedValueException

standard

Dynamic Library Support => enabled
Path to sendmail => /usr/sbin/sendmail -t -i 

Directive => Local Value => Master Value
assert.active => 1 => 1
assert.bail => 0 => 0
assert.callback => no value => no value
assert.quiet_eval => 0 => 0
assert.warning => 1 => 1
auto_detect_line_endings => 0 => 0
default_socket_timeout => 60 => 60
from => no value => no value
url_rewriter.tags => a=href,area=href,frame=src,input=src,form=fakeentry => a=href,area=href,frame=src,input=src,form=fakeentry
user_agent => no value => no value

sysvmsg

sysvmsg support => enabled
Revision => $Id: adf1d2d6be849c46eed3c3ee6f1cbebd1448d6e5 $

tokenizer

Tokenizer Support => enabled

uopz

uopz support => enabled

wddx

WDDX Support => enabled
WDDX Session Serializer => enabled

xdebug

xdebug support => enabled
Version => 2.2.6
IDE Key => jean

Supported protocols => Revision
DBGp - Common DeBuGger Protocol => $Revision: 1.145 $

Directive => Local Value => Master Value
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.extended_info => On => On
xdebug.file_link_format => no value => no value
xdebug.idekey => no value => no value
xdebug.max_nesting_level => 100 => 100
xdebug.overload_var_dump => On => On
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_autostart => Off => Off
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => Off => Off
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.scream => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3

xml

XML Support => active
XML Namespace Support => active
libxml2 Version => 2.9.2

xmlreader

XMLReader => enabled

xmlwriter

XMLWriter => enabled

Zend OPcache

Opcode Caching => Disabled
Optimization => Disabled
Startup Failed => Opcode Caching is disabled for CLI

Directive => Local Value => Master Value
opcache.blacklist_filename => no value => no value
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => Off => Off
opcache.enable_file_override => Off => Off
opcache.error_log => no value => no value
opcache.fast_shutdown => 0 => 0
opcache.file_update_protection => 2 => 2
opcache.force_restart_timeout => 180 => 180
opcache.inherited_hack => On => On
opcache.interned_strings_buffer => 4 => 4
opcache.load_comments => 1 => 1
opcache.log_verbosity_level => 1 => 1
opcache.max_accelerated_files => 2000 => 2000
opcache.max_file_size => 0 => 0
opcache.max_wasted_percentage => 5 => 5
opcache.memory_consumption => 64 => 64
opcache.optimization_level => 0xFFFFFFFF => 0xFFFFFFFF
opcache.preferred_memory_model => no value => no value
opcache.protect_memory => 0 => 0
opcache.restrict_api => no value => no value
opcache.revalidate_freq => 2 => 2
opcache.revalidate_path => Off => Off
opcache.save_comments => 1 => 1
opcache.use_cwd => On => On
opcache.validate_timestamps => On => On

zip

Zip => enabled
Extension Version => $Id: a9a55a8aeff3110d7c004145748c9adbf990eec3 $
Zip version => 1.12.4
Libzip version => 0.11.2

zlib

ZLib Support => enabled
Stream Wrapper => compress.zlib://
Stream Filter => zlib.inflate, zlib.deflate
Compiled Version => 1.2.8
Linked Version => 1.2.8

Directive => Local Value => Master Value
zlib.output_compression => Off => Off
zlib.output_compression_level => -1 => -1
zlib.output_handler => no value => no value

Additional Modules

Module Name
sysvsem
sysvshm

Environment

Variable => Value
LESSOPEN => | /usr/bin/lesspipe %s
GNOME_KEYRING_PID =>  
USER => jean
LANGUAGE => fr_FR
UPSTART_INSTANCE =>  
SSH_CLIENT => deleted
XDG_SEAT => seat0
SESSION => xubuntu
XDG_SESSION_TYPE => x11
SHLVL => 1
OLDPWD => /home/jean/dev/www/<mycompany>/QA/resources/php-test-helpers
HOME => /home/jean
QT4_IM_MODULE =>  
DESKTOP_SESSION => xubuntu
SSH_TTY => deleted
XDG_SEAT_PATH => /org/freedesktop/DisplayManager/Seat0
INSTANCE =>  
DBUS_SESSION_BUS_ADDRESS => unix:abstract=/tmp/dbus-ntQHAn58iW
GLADE_MODULE_PATH => :
COLORTERM => xfce4-terminal
GNOME_KEYRING_CONTROL =>  
MANDATORY_PATH => /usr/share/gconf/xubuntu.mandatory.path
IM_CONFIG_PHASE => 1
SESSIONTYPE =>  
UPSTART_JOB => startxfce4
LOGNAME => jean
GTK_IM_MODULE =>  
WINDOWID => 62990903
TEST_PHP_EXECUTABLE => /usr/bin/php
_ => /usr/bin/php
DEFAULTS_PATH => /usr/share/gconf/xubuntu.default.path
XDG_SESSION_ID => c1
TERM => xterm
PATH => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
GLADE_PIXMAP_PATH => :
SESSION_MANAGER => local/jean-Lenovo-G580:@/tmp/.ICE-unix/1521,unix/jean-Lenovo-G580:/tmp/.ICE-unix/1521
GDM_LANG => fr_FR
XDG_MENU_PREFIX => xfce-
XDG_SESSION_PATH => /org/freedesktop/DisplayManager/Session0
XDG_RUNTIME_DIR => /run/user/1000
DISPLAY => :0.0
LANG => fr_FR.UTF-8
XDG_CURRENT_DESKTOP => XFCE
LS_COLORS => rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
XMODIFIERS =>  
XDG_SESSION_DESKTOP => xubuntu
XAUTHORITY => /home/jean/.Xauthority
XDG_GREETER_DATA_DIR => /var/lib/lightdm-data/jean
SSH_AUTH_SOCK => deleted
GLADE_CATALOG_PATH => :
SHELL => /bin/bash
GDMSESSION => xubuntu
LESSCLOSE => /usr/bin/lesspipe %s %s
UPSTART_EVENTS => started xsession
GPG_AGENT_INFO => /run/user/1000/keyring/gpg:0:1
UPSTART_SESSION => unix:abstract=/com/ubuntu/upstart-session/1000/983
XDG_VTNR => 7
QT_IM_MODULE =>  
PWD => /home/jean/dev/www/<mycompany>/QA/resources/uopz
CLUTTER_IM_MODULE =>  
XDG_CONFIG_DIRS => /etc/xdg/xdg-xubuntu:/usr/share/upstart/xdg:/etc/xdg:/etc/xdg
XDG_DATA_DIRS => /usr/share/xubuntu:/usr/share/xfce4:/usr/local/share/:/usr/share/:/usr/share
SSH_CONNECTION => deleted
JOB => dbus

PHP Variables

Variable => Value
_SERVER["LESSOPEN"] => | /usr/bin/lesspipe %s
_SERVER["GNOME_KEYRING_PID"] => 
_SERVER["USER"] => jean
_SERVER["LANGUAGE"] => fr_FR
_SERVER["UPSTART_INSTANCE"] => 
_SERVER["SSH_CLIENT"] => deleted
_SERVER["XDG_SEAT"] => seat0
_SERVER["SESSION"] => xubuntu
_SERVER["XDG_SESSION_TYPE"] => x11
_SERVER["SHLVL"] => 1
_SERVER["OLDPWD"] => /home/jean/dev/www/<mycompany>/QA/resources/php-test-helpers
_SERVER["HOME"] => /home/jean
_SERVER["QT4_IM_MODULE"] => 
_SERVER["DESKTOP_SESSION"] => xubuntu
_SERVER["SSH_TTY"] => deleted
_SERVER["XDG_SEAT_PATH"] => /org/freedesktop/DisplayManager/Seat0
_SERVER["INSTANCE"] => 
_SERVER["DBUS_SESSION_BUS_ADDRESS"] => unix:abstract=/tmp/dbus-ntQHAn58iW
_SERVER["GLADE_MODULE_PATH"] => :
_SERVER["COLORTERM"] => xfce4-terminal
_SERVER["GNOME_KEYRING_CONTROL"] => 
_SERVER["MANDATORY_PATH"] => /usr/share/gconf/xubuntu.mandatory.path
_SERVER["IM_CONFIG_PHASE"] => 1
_SERVER["SESSIONTYPE"] => 
_SERVER["UPSTART_JOB"] => startxfce4
_SERVER["LOGNAME"] => jean
_SERVER["GTK_IM_MODULE"] => 
_SERVER["WINDOWID"] => 62990903
_SERVER["TEST_PHP_EXECUTABLE"] => /usr/bin/php
_SERVER["_"] => /usr/bin/php
_SERVER["DEFAULTS_PATH"] => /usr/share/gconf/xubuntu.default.path
_SERVER["XDG_SESSION_ID"] => c1
_SERVER["TERM"] => xterm
_SERVER["PATH"] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
_SERVER["GLADE_PIXMAP_PATH"] => :
_SERVER["SESSION_MANAGER"] => local/jean-Lenovo-G580:@/tmp/.ICE-unix/1521,unix/jean-Lenovo-G580:/tmp/.ICE-unix/1521
_SERVER["GDM_LANG"] => fr_FR
_SERVER["XDG_MENU_PREFIX"] => xfce-
_SERVER["XDG_SESSION_PATH"] => /org/freedesktop/DisplayManager/Session0
_SERVER["XDG_RUNTIME_DIR"] => /run/user/1000
_SERVER["DISPLAY"] => :0.0
_SERVER["LANG"] => fr_FR.UTF-8
_SERVER["XDG_CURRENT_DESKTOP"] => XFCE
_SERVER["LS_COLORS"] => rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
_SERVER["XMODIFIERS"] => 
_SERVER["XDG_SESSION_DESKTOP"] => xubuntu
_SERVER["XAUTHORITY"] => /home/jean/.Xauthority
_SERVER["XDG_GREETER_DATA_DIR"] => /var/lib/lightdm-data/jean
_SERVER["SSH_AUTH_SOCK"] => deleted
_SERVER["GLADE_CATALOG_PATH"] => :
_SERVER["SHELL"] => /bin/bash
_SERVER["GDMSESSION"] => xubuntu
_SERVER["LESSCLOSE"] => /usr/bin/lesspipe %s %s
_SERVER["UPSTART_EVENTS"] => started xsession
_SERVER["GPG_AGENT_INFO"] => /run/user/1000/keyring/gpg:0:1
_SERVER["UPSTART_SESSION"] => unix:abstract=/com/ubuntu/upstart-session/1000/983
_SERVER["XDG_VTNR"] => 7
_SERVER["QT_IM_MODULE"] => 
_SERVER["PWD"] => /home/jean/dev/www/<mycompany>/QA/resources/uopz
_SERVER["CLUTTER_IM_MODULE"] => 
_SERVER["XDG_CONFIG_DIRS"] => /etc/xdg/xdg-xubuntu:/usr/share/upstart/xdg:/etc/xdg:/etc/xdg
_SERVER["XDG_DATA_DIRS"] => /usr/share/xubuntu:/usr/share/xfce4:/usr/local/share/:/usr/share/:/usr/share
_SERVER["SSH_CONNECTION"] => deleted
_SERVER["JOB"] => dbus
_SERVER["PHP_SELF"] => 
_SERVER["SCRIPT_NAME"] => 
_SERVER["SCRIPT_FILENAME"] => 
_SERVER["PATH_TRANSLATED"] => 
_SERVER["DOCUMENT_ROOT"] => 
_SERVER["REQUEST_TIME_FLOAT"] => 1443454316.1524
_SERVER["REQUEST_TIME"] => 1443454316
_SERVER["argv"] => Array
(
)

_SERVER["argc"] => 0

PHP License
This program is free software; you can redistribute it and/or modify
it under the terms of the PHP License as published by the PHP Group
and included in the distribution in the file:  LICENSE

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you did not receive a copy of the PHP license, or have any
questions about PHP licensing, please contact [email protected].

List Supported PHP Version(s)

I couldn't easily find the supported versions of PHP in the README, and while it might be obvious to some - or that a good majority of users are on 5.4 and above, for some of us unlucky folk who are stuck on 5.3 (stuck behind the 🎱 unfortunately) it would be nice to have that reminder that we need to affect change and upgrade our PHP version. :)

uopz_rename

Hi!
Is there any possibility for uopz_rename to come back? This is a very handy functionality, allowing to rename original method, add the new one and call original from the overriding method. Currently I found no possibility for that :(

[5.0.2] phar issue

$ php -d uopz.disable=1 /usr/bin/phar
No command given, check /usr/bin/phar help

$ php -d uopz.disable= /usr/bin/phar
No command given, check /usr/bin/phar help
PHP Notice:  Undefined variable: command in phar:///usr/bin/phar.phar/clicommand.inc on line 40
PHP Notice:  Undefined variable: command in phar:///usr/bin/phar.phar/clicommand.inc on line 87
PHP Notice:  Undefined index:  in phar:///usr/bin/phar.phar/clicommand.inc on line 87
PHP Warning:  uopz_call_user_func() expects parameter 1 to be a valid callback, second array member is not a valid method in phar:///usr/bin/phar.phar/clicommand.inc on line 87

Also sebastianbergmann/phpunit#2753

die() not echoing

php.ini

PHP 5.6.0-dev (cli) (built: Jul 13 2014 12:53:51)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0-dev, Copyright (c) 1998-2014 Zend Technologies
    with uopz v2.0.5, Copyright (c) 2014, by Joe Watkins <[email protected]>
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

With the above I am trying die('wtf'); and nothing is printing in web and cli.

having disabled uopz it now prints but I am getting this error now

bash: __vcs_name: command not found

Conflict with APC

The following script gets HTTP 500 error, It runs on apache with fastcgi mode.

<?php
require 'vendor/autoload.php';
FreeBSD machine 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013     [email protected]:/usr/obj/usr/src/sys/GENERIC  amd64
PHP 5.4.21 (cli) (built: Nov  8 2013 02:52:35)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
    with test_helpers v1.0.1-dev, Copyright (c) 2009-2010, by Johannes Schlueter, Scott MacVicar, Sebastian Bergmann
apc

APC Support => disabled
Version => 3.1.13
apc.cache_by_default => On => On
apc.canonicalize => On => On
apc.coredump_unmap => Off => Off
apc.enable_cli => Off => Off
apc.enabled => On => On
apc.file_md5 => Off => Off
apc.file_update_protection => 2 => 2
apc.filters => no value => no value
apc.gc_ttl => 3600 => 3600
apc.include_once_override => Off => Off
apc.lazy_classes => Off => Off
apc.lazy_functions => Off => Off
apc.max_file_size => 1M => 1M
apc.mmap_file_mask => no value => no value
apc.num_files_hint => 1000 => 1000
apc.preload_path => no value => no value
apc.report_autofilter => Off => Off
apc.rfc1867 => Off => Off
apc.rfc1867_freq => 0 => 0
apc.rfc1867_name => APC_UPLOAD_PROGRESS => APC_UPLOAD_PROGRESS
apc.rfc1867_prefix => upload_ => upload_
apc.rfc1867_ttl => 3600 => 3600
apc.serializer => default => default
apc.shm_segments => 1 => 1
apc.shm_size => 128M => 128M
apc.shm_strings_buffer => 4M => 4M
apc.slam_defense => On => On
apc.stat => On => On
apc.stat_ctime => On => On
apc.ttl => 0 => 0
apc.use_request_time => On => On
apc.user_entries_hint => 4096 => 4096
apc.user_ttl => 0 => 0
apc.write_lock => On => On

opcache do not update class constant after uopz_redefine

see https://bugs.php.net/bug.php?id=74576

Description:

I use uopz_redefine to redefine class constants
(uopz called zend_declare_class_constant)

when opcache is enabled, I cannot get the new class constant through Foo::BAR.

Test script:

<?php

class Foo
{
	const BAR = '123';
}

var_dump(Foo::BAR);// A1: try to comment this

(function () {
	var_dump(Foo::BAR);	// B1: try to comment this
	uopz_redefine('Foo', 'BAR', '456');
	var_dump(Foo::BAR);	// B2: compare
})();

(function () {
	var_dump(Foo::BAR);	// new scope
})();

var_dump((new ReflectionClass('Foo'))->getConstant('BAR'));	// also OK

var_dump(Foo::BAR);	// A2: compare

Expected result:

'123'
'123'
'456'
'456'
'456'
'456'

Actual result:

'123'
'123'
'123' (it is '456' if line B1 is commented)
'456'
'456'
'123' (it is '456' if line A1 is commented)

uopz_set_return and uopz_set_hook apply to parents of class

class Bar {
    public function test() {
        return "Bar::test\n";
    }
}

class Foo extends Bar {
    public function test() {
        return "Foo::test\n";
    }
}

echo "Before set return\n";
echo (new Foo)->test();
echo (new Bar)->test();
uopz_set_return(Foo::class, 'test', "redefined return\n");
echo "After set return\n";
echo (new Foo)->test();
echo (new Bar)->test();
uopz_unset_return(Foo::class, 'test');
echo "After unset return\n";
echo (new Foo)->test();
echo (new Bar)->test();

output

Before set return
Foo::test
Bar::test
After set return
redefined return
redefined return
After unset return
Foo::test
redefined return

same with uopz_set_hook

Failing tests on OSX and Amazon Linux

I get the following failing test on OSX

Software  OS X 10.9.5 (13F34)

Test run by phpunit

PHPUnit 4.3.5 by Sebastian Bergmann.

.FF.............................FF............

Time: 8.53 seconds, Memory: 3.75Mb

There were 4 failures:

1) /private/tmp/uopz-2.0.6/tests/002.phpt
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
-bool(true)
+bool(false)
 bool(true)

2) /private/tmp/uopz-2.0.6/tests/003.phpt
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
-bool(true)
+bool(false)

3) /private/tmp/uopz-2.0.6/tests/034.phpt
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
-object(test)#%d (%d) {
-}
-array(1) {
-  ["mine"]=>
-  string(4) "mine"
-}
+Fatal error: Class 'other' not found in - on line 9

4) /private/tmp/uopz-2.0.6/tests/035.phpt
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
-object(test)#%d (%d) {
-  ["arg":protected]=>
-  object(stdClass)#%d (0) {
-  }
-}
-array(1) {
-  ["TestBundle"]=>
-  string(10) "TestBundle"
-}
+Fatal error: Class 'test' not found in - on line 26

FAILURES!
Tests: 46, Assertions: 46, Failures: 4.

php -v

PHP 5.5.20 (cli) (built: Jan  6 2015 12:30:39)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with uopz v2.0.6, Copyright (c) 2014, by Joe Watkins <[email protected]>
    with Xdebug v2.2.6, Copyright (c) 2002-2014, by Derick Rethans

And i get the same on Amazon Linux

NAME="Amazon Linux AMI"
VERSION="2014.09"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2014.09"
PRETTY_NAME="Amazon Linux AMI 2014.09"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2014.09:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"

Test run by phpunit

PHPUnit 4.4.2 by Sebastian Bergmann.

.FF.............................FF............

Time: 1.89 seconds, Memory: 3.75Mb

There were 4 failures:

1) /tmp/uopz-2.0.6/tests/002.phpt
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
-bool(true)
+bool(false)
 bool(true)

2) /tmp/uopz-2.0.6/tests/003.phpt
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
-bool(true)
+bool(false)

3) /tmp/uopz-2.0.6/tests/034.phpt
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
-object(test)#%d (%d) {
-}
-array(1) {
-  ["mine"]=>
-  string(4) "mine"
-}
+Fatal error: Class 'other' not found in - on line 9

4) /tmp/uopz-2.0.6/tests/035.phpt
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
-object(test)#%d (%d) {
-  ["arg":protected]=>
-  object(stdClass)#%d (0) {
-  }
-}
-array(1) {
-  ["TestBundle"]=>
-  string(10) "TestBundle"
-}
+Fatal error: Class 'test' not found in - on line 26

FAILURES!
Tests: 46, Assertions: 46, Failures: 4.

php -v

PHP 5.5.18 (cli) (built: Oct 27 2014 20:24:54)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with uopz v2.0.6, Copyright (c) 2014, by Joe Watkins <[email protected]>
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
NAME="Amazon Linux AMI"
VERSION="2014.09"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2014.09"
PRETTY_NAME="Amazon Linux AMI 2014.09"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2014.09:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"

Failing tests on OSX and Amazon Linux

There a 4 failing tests on Amazon Linux and on OSX, among overwriting ZEND_NEW.

Amazon Linux

[root@NAME build]# TEST_PHP_EXECUTABLE=/usr/bin/php php run-tests.php /tmp/uopz/tests/

=====================================================================
PHP         : /usr/bin/php
PHP_SAPI    : cli
PHP_VERSION : 5.5.18
ZEND_VERSION: 2.5.0
PHP_OS      : Linux - Linux NAME.DOMAIN.COM 3.14.19-17.43.amzn1.x86_64 #1 SMP Wed Sep 17 22:14:52 UTC 2014 x86_64
INI actual  : /etc/php-5.5.ini
More .INIs  : /etc/php-5.5.d/bz2.ini,/etc/php-5.5.d/calendar.ini,/etc/php-5.5.d/ctype.ini,/etc/php-5.5.d/curl.ini,/etc/php-5.5.d/dom.ini,/etc/php-5.5.d/exif.ini,/etc/php-5.5.d/fileinfo.ini,/etc/php-5.5.d/ftp.ini,/etc/php-5.5.d/gettext.ini,/etc/php-5.5.d/iconv.ini,/etc/php-5.5.d/intl.ini,/etc/php-5.5.d/json.ini,/etc/php-5.5.d/mbstring.ini,/etc/php-5.5.d/mcrypt.ini,/etc/php-5.5.d/memcached.ini,/etc/php-5.5.d/mysqlnd.ini,/etc/php-5.5.d/mysqlnd_mysql.ini,/etc/php-5.5.d/mysqlnd_mysqli.ini,/etc/php-5.5.d/pdo.ini,/etc/php-5.5.d/pdo_mysqlnd.ini,/etc/php-5.5.d/pdo_sqlite.ini,/etc/php-5.5.d/phar.ini,/etc/php-5.5.d/php.ini,/etc/php-5.5.d/posix.ini,/etc/php-5.5.d/shmop.ini,/etc/php-5.5.d/simplexml.ini,/etc/php-5.5.d/soap.ini,/etc/php-5.5.d/sockets.ini,/etc/php-5.5.d/sqlite3.ini,/etc/php-5.5.d/stem.ini,/etc/php-5.5.d/sysvmsg.ini,/etc/php-5.5.d/sysvsem.ini,/etc/php-5.5.d/sysvshm.ini,/etc/php-5.5.d/tokenizer.ini,/etc/php-5.5.d/uopz.ini,/etc/php-5.5.d/xdebug.ini,/etc/php-5.5.d/xml.ini,/etc/php-5.5.d/xml_wddx.ini,/etc/php-5.5.d/xmlreader.ini,/etc/php-5.5.d/xmlwriter.ini,/etc/php-5.5.d/xsl.ini,/etc/php-5.5.d/zip.ini
CWD         : /usr/lib64/php/5.5/build
Extra dirs  :
VALGRIND    : Not used
=====================================================================
Running selected tests.
PASS Test exit overload [/tmp/uopz/tests/001.phpt]
FAIL Test new overload [/tmp/uopz/tests/002.phpt]
FAIL Test add trait [/tmp/uopz/tests/003.phpt]
PASS Test add interface [/tmp/uopz/tests/004.phpt]
PASS Test instancoef [/tmp/uopz/tests/005.phpt]
PASS Test throw [/tmp/uopz/tests/006.phpt]
PASS Test rename [/tmp/uopz/tests/007.phpt]
PASS Test redefine [/tmp/uopz/tests/008.phpt]
PASS Test delete [/tmp/uopz/tests/010.phpt]
PASS Test undefine/redefine [/tmp/uopz/tests/011.phpt]
PASS Test implement [/tmp/uopz/tests/012.phpt]
PASS Test extend [/tmp/uopz/tests/013.phpt]
PASS Test compose [/tmp/uopz/tests/014.phpt]
PASS Test override [/tmp/uopz/tests/015.phpt]
PASS Test magic methods [/tmp/uopz/tests/016.phpt]
PASS Test backup/restore [/tmp/uopz/tests/017.phpt]
PASS Test backup/restore user functions [/tmp/uopz/tests/018.phpt]
PASS Test auto restore user functions [/tmp/uopz/tests/019.phpt]
PASS Test auto restore internals [/tmp/uopz/tests/020.phpt]
PASS Test backup/restore user methods [/tmp/uopz/tests/021.phpt]
PASS Test auto restore user methods [/tmp/uopz/tests/022.phpt]
PASS Test backup/restore internal methods [/tmp/uopz/tests/023.phpt]
PASS Test auto restore internal methods [/tmp/uopz/tests/024.phpt]
PASS Test copy user functions [/tmp/uopz/tests/025.phpt]
PASS Test backup/restore/rename combination [/tmp/uopz/tests/026.phpt]
PASS Test use original function [/tmp/uopz/tests/027.phpt]
PASS Test compose interface [/tmp/uopz/tests/028.phpt]
PASS Test compose trait [/tmp/uopz/tests/029.phpt]
PASS Test sane composition of normal classes [/tmp/uopz/tests/030.phpt]
PASS Test sane composition of interfaces [/tmp/uopz/tests/031.phpt]
PASS Test sane composition of traits [/tmp/uopz/tests/032.phpt]
PASS Test sane use of traits and interfaces [/tmp/uopz/tests/033.phpt]
FAIL Test fetch class overload [/tmp/uopz/tests/034.phpt]
FAIL Test fetch class and compose [/tmp/uopz/tests/035.phpt]
PASS Test modifiers on functions [/tmp/uopz/tests/036.phpt]
PASS Test modifiers on functions are copied by default [/tmp/uopz/tests/037.phpt]
PASS Test complicated construction of classes [/tmp/uopz/tests/038.phpt]
PASS Test bug in finding functions [/tmp/uopz/tests/039.phpt]
PASS Test bug in finding private user functions [/tmp/uopz/tests/040.phpt]
PASS Test creation of properties when composing [/tmp/uopz/tests/041.phpt]
PASS Test sensible extend operation [/tmp/uopz/tests/042.phpt]
PASS Test compose error conditions (interface with properties) [/tmp/uopz/tests/043.phpt]
PASS Test overload error conditions for bad handlers [/tmp/uopz/tests/044.phpt]
PASS Test uopz_function with global function and modifiers [/tmp/uopz/tests/045.phpt]
PASS Test uopz_delete cleans up magic [/tmp/uopz/tests/046.phpt]
PASS Test uopz_flags operation [/tmp/uopz/tests/047.phpt]
=====================================================================
Number of tests :   46                46
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    4 (  8.7%) (  8.7%)
Expected fail   :    0 (  0.0%) (  0.0%)
Tests passed    :   42 ( 91.3%) ( 91.3%)
---------------------------------------------------------------------
Time taken      :    1 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Test new overload [/tmp/uopz/tests/002.phpt]
Test add trait [/tmp/uopz/tests/003.phpt]
Test fetch class overload [/tmp/uopz/tests/034.phpt]
Test fetch class and compose [/tmp/uopz/tests/035.phpt]
=====================================================================

OSX

jach@jach:...4.14-20130505-195324/lib/build (master)$ TEST_PHP_EXECUTABLE=/usr/local/bin/php php run-tests.php /tmp/uopz/tests/

=====================================================================
PHP         : /usr/local/bin/php
PHP_SAPI    : cli
PHP_VERSION : 5.5.20
ZEND_VERSION: 2.5.0
PHP_OS      : Darwin - Darwin jach 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
INI actual  : /usr/local/etc/php/5.5/php.ini
More .INIs  : /usr/local/etc/php/5.5/conf.d/ext-mcrypt.ini,/usr/local/etc/php/5.5/conf.d/ext-memcached.ini,/usr/local/etc/php/5.5/conf.d/ext-xdebug.ini
CWD         : /usr/local/php5-5.4.14-20130505-195324/lib/build
Extra dirs  :
VALGRIND    : Not used
=====================================================================
Running selected tests.
PASS Test exit overload [/private/tmp/uopz/tests/001.phpt]
FAIL Test new overload [/private/tmp/uopz/tests/002.phpt]
FAIL Test add trait [/private/tmp/uopz/tests/003.phpt]
PASS Test add interface [/private/tmp/uopz/tests/004.phpt]
PASS Test instancoef [/private/tmp/uopz/tests/005.phpt]
PASS Test throw [/private/tmp/uopz/tests/006.phpt]
PASS Test rename [/private/tmp/uopz/tests/007.phpt]
PASS Test redefine [/private/tmp/uopz/tests/008.phpt]
PASS Test delete [/private/tmp/uopz/tests/010.phpt]
PASS Test undefine/redefine [/private/tmp/uopz/tests/011.phpt]
PASS Test implement [/private/tmp/uopz/tests/012.phpt]
PASS Test extend [/private/tmp/uopz/tests/013.phpt]
PASS Test compose [/private/tmp/uopz/tests/014.phpt]
PASS Test override [/private/tmp/uopz/tests/015.phpt]
PASS Test magic methods [/private/tmp/uopz/tests/016.phpt]
PASS Test backup/restore [/private/tmp/uopz/tests/017.phpt]
PASS Test backup/restore user functions [/private/tmp/uopz/tests/018.phpt]
PASS Test auto restore user functions [/private/tmp/uopz/tests/019.phpt]
PASS Test auto restore internals [/private/tmp/uopz/tests/020.phpt]
PASS Test backup/restore user methods [/private/tmp/uopz/tests/021.phpt]
PASS Test auto restore user methods [/private/tmp/uopz/tests/022.phpt]
PASS Test backup/restore internal methods [/private/tmp/uopz/tests/023.phpt]
PASS Test auto restore internal methods [/private/tmp/uopz/tests/024.phpt]
PASS Test copy user functions [/private/tmp/uopz/tests/025.phpt]
PASS Test backup/restore/rename combination [/private/tmp/uopz/tests/026.phpt]
PASS Test use original function [/private/tmp/uopz/tests/027.phpt]
PASS Test compose interface [/private/tmp/uopz/tests/028.phpt]
PASS Test compose trait [/private/tmp/uopz/tests/029.phpt]
PASS Test sane composition of normal classes [/private/tmp/uopz/tests/030.phpt]
PASS Test sane composition of interfaces [/private/tmp/uopz/tests/031.phpt]
PASS Test sane composition of traits [/private/tmp/uopz/tests/032.phpt]
PASS Test sane use of traits and interfaces [/private/tmp/uopz/tests/033.phpt]
FAIL Test fetch class overload [/private/tmp/uopz/tests/034.phpt]
FAIL Test fetch class and compose [/private/tmp/uopz/tests/035.phpt]
PASS Test modifiers on functions [/private/tmp/uopz/tests/036.phpt]
PASS Test modifiers on functions are copied by default [/private/tmp/uopz/tests/037.phpt]
PASS Test complicated construction of classes [/private/tmp/uopz/tests/038.phpt]
PASS Test bug in finding functions [/private/tmp/uopz/tests/039.phpt]
PASS Test bug in finding private user functions [/private/tmp/uopz/tests/040.phpt]
PASS Test creation of properties when composing [/private/tmp/uopz/tests/041.phpt]
PASS Test sensible extend operation [/private/tmp/uopz/tests/042.phpt]
PASS Test compose error conditions (interface with properties) [/private/tmp/uopz/tests/043.phpt]
PASS Test overload error conditions for bad handlers [/private/tmp/uopz/tests/044.phpt]
PASS Test uopz_function with global function and modifiers [/private/tmp/uopz/tests/045.phpt]
PASS Test uopz_delete cleans up magic [/private/tmp/uopz/tests/046.phpt]
PASS Test uopz_flags operation [/private/tmp/uopz/tests/047.phpt]
=====================================================================
Number of tests :   46                46
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    4 (  8.7%) (  8.7%)
Expected fail   :    0 (  0.0%) (  0.0%)
Tests passed    :   42 ( 91.3%) ( 91.3%)
---------------------------------------------------------------------
Time taken      :    9 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Test new overload [/private/tmp/uopz/tests/002.phpt]
Test add trait [/private/tmp/uopz/tests/003.phpt]
Test fetch class overload [/private/tmp/uopz/tests/034.phpt]
Test fetch class and compose [/private/tmp/uopz/tests/035.phpt]
=====================================================================

block optimization (opcache) fails when exit is overloaded

<?php
class Uopz_Test extends PHPUnit_Framework_TestCase
{

    public function testExit()
    {
        uopz_overload(ZEND_EXIT, function($status = 0) { return false; });
        exit();
        uopz_overload(ZEND_EXIT, null);
    }

}
?>

Still researching the problem ... this bug is present only in the last release (2.0.7)

Unconditional exit code overloading

This is just a @alexjay 's comment copy from #2


I expiriencing the same trouble with uopz 2.0.6. Exit code spicified in exit() is missing.

How to reproduce:

enable uopz

zend_extension=uopz.so

create test.php file with exit

<?php
exit(42);

run it

php test.php; echo $?

expected is 42
actual is 0

Exit code will be 0 regardless the value that was specified in the script.
I've tried to remove php_uopz_overload_exit at zend extension initialization and recomplie the uopz extension... and it helped. It seems that the default exit() uopz handler misses its exit code.


We simply removed exit overloading from uopz since we don't need it so far, but others can experience the same problem even not noticing it. So proper patch would be nice.

uopz doesn't work on Windows if a replaced function was called before from a function

The following code that works perfectly fine on Linux (output should be a random byte in hex and then ffffffff) does not work on Windows (PHP 5.6.14, tried both x64 and x86, TS and NTS builds, enabled and disabled opcache, uopz binary 2.0.7 from https://pecl.php.net/package/uopz).

<?php

function printRandomByte() {
    echo bin2hex(openssl_random_pseudo_bytes(1)) . "\n";
}

printRandomByte();
uopz_backup('openssl_random_pseudo_bytes');
uopz_function('openssl_random_pseudo_bytes', function($length, &$strong = null) {
    return hex2bin('ffffffff');
});
printRandomByte();
uopz_restore('openssl_random_pseudo_bytes');

It just outputs two random bytes instead (as if the openssl_random_pseudo_byte function wasn't replaced at all).

If I remove the first printRandomByte() call before the uopz_backup, then it works. If I remove the first call plus add a printRandomByte() call after the uopz_restore, PHP crashes.

If I replace the printRandomByte(); calls with just the function body (echo bin2hex(openssl_random_pseudo_bytes(1)) . "\n";), then it works as it should.

It behaves similarly for other functions (I also tried time())

Test failing on PHP 5.4.39 on CentOS

I installed uopz using the pecl installer. In phpinfo() it seems to be installed perfectly. Then I added uopz.overloads=1 in php.ini.

Then I tried to run the first test and it worked well.
But the second test fails.

Here is my PHP code:

uopz_overload(ZEND_FETCH_CLASS,
    function (&$class) {
        if ($class == "stdClass") {
            $class = "myClass";
        }
    });

class myClass {
}

$class = new stdClass();
var_dump($class instanceof myClass);
uopz_overload(ZEND_NEW, null);
$class = new stdClass();
var_dump($class instanceof stdClass);

Output is:

boolean false
boolean true

The anonymous overload function does not get executed.

Have I configured something wrong?

Segfault after uopz_set_static()

Running this causes an invalid read in both current PHP 7.1 and 7.2:

<?php
class A {
    function fn() {
        static $a = 1;
        $a++;
    }
}

print_r(uopz_get_static(A::class, "fn"));
uopz_set_static(A::class, "fn", ['a'=>3, 'b'=>7]);
$a = new A;
$a->fn();
print_r(uopz_get_static(A::class, "fn"));

The gdb output from PHP 7.2 is:

Array
(
    [a] => 1
)

Program received signal SIGSEGV, Segmentation fault.
ZEND_BIND_STATIC_SPEC_CV_CONST_HANDLER () at /home/rasmus/php-src/Zend/zend_vm_execute.h:38342
warning: Source file is more recent than executable.
38342		SAVE_OPLINE();
(gdb) zbacktrace
[0x7fffeca1b0a0] A->fn() /home/rasmus/t7:4 
[0x7fffeca1b030] (main) /home/rasmus/t7:12 
(gdb) bt
#0  ZEND_BIND_STATIC_SPEC_CV_CONST_HANDLER () at /home/rasmus/php-src/Zend/zend_vm_execute.h:38342
#1  0x0000555555b52ceb in execute_ex (ex=<optimized out>) at /home/rasmus/php-src/Zend/zend_vm_execute.h:429
#2  0x0000555555bad466 in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER () at /home/rasmus/php-src/Zend/zend_vm_execute.h:935
#3  0x0000555555b52ceb in execute_ex (ex=<optimized out>) at /home/rasmus/php-src/Zend/zend_vm_execute.h:429
#4  0x0000555555bad8b8 in zend_execute (op_array=op_array@entry=0x7fffeca7d2a0, return_value=return_value@entry=0x7fffeca0b9b8) at /home/rasmus/php-src/Zend/zend_vm_execute.h:474
#5  0x0000555555b0c025 in zend_execute_scripts (type=-324947808, type@entry=8, retval=0x7fffeca0b9b8, retval@entry=0x0, file_count=file_count@entry=3) at /home/rasmus/php-src/Zend/zend.c:1537
#6  0x0000555555aab3c0 in php_execute_script (primary_file=0x7fffffffd1f0) at /home/rasmus/php-src/main/main.c:2548
#7  0x0000555555bafcad in do_cli (argc=2, argv=0x5555566a0f30) at /home/rasmus/php-src/sapi/cli/php_cli.c:997
#8  0x00005555556c6746 in main (argc=2, argv=0x5555566a0f30) at /home/rasmus/php-src/sapi/cli/php_cli.c:1390

And Valgrind says it is an invalid read here:

==17318== Invalid read of size 1
==17318==    at 0x70B610: ZEND_BIND_STATIC_SPEC_CV_CONST_HANDLER (zend_vm_execute.h:38342)
==17318==    by 0x706CEA: execute_ex (zend_vm_execute.h:429)
==17318==    by 0x761465: ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER (zend_vm_execute.h:935)
==17318==    by 0x706CEA: execute_ex (zend_vm_execute.h:429)
==17318==    by 0x7618B7: zend_execute (zend_vm_execute.h:474)
==17318==    by 0x6C0024: zend_execute_scripts (zend.c:1537)
==17318==    by 0x65F3BF: php_execute_script (main.c:2548)
==17318==    by 0x763CAC: do_cli (php_cli.c:997)
==17318==    by 0x27A745: main (php_cli.c:1390)
==17318==  Address 0x9 is not stack'd, malloc'd or (recently) free'd

Request: Tagged release

last release is quite a while back and isn't building against 7.1 for a lot of people.
A new "convenience release" as you called it for 5.0.1 would be much appreciated.

uopz messing with exit;

This cli script with uopz loaded:

<?php
echo 1;
echo 2;
echo 3;
exit(0);
echo 4;
echo 5;
echo 6;

will output: 123456

PHP 7.1

Hi There,
Is there a timeline for PHP 7.1 support?
-Thanks

Installation error

Hi,
I'm trying to install uopz inside my OSX(Sierra) with php7.1

I have done this:

sudo pecl install uopz

But it can't install and this is the output of some errors, how can I install this extension?



/private/tmp/pear/temp/uopz/src/class.c:134:31: error: no member named 'scope' in 'struct _zend_executor_globals'
        zend_class_entry *scope = EG(scope);
                                  ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:139:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = ce;
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:151:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = info->ce;
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:153:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = Z_OBJCE_P(object);
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:159:5: error: no member named 'scope' in 'struct _zend_executor_globals'
        EG(scope) = scope;
        ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:163:31: error: no member named 'scope' in 'struct _zend_executor_globals'
        zend_class_entry *scope = EG(scope);
                                  ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:169:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = ce;
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:181:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = info->ce;
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:183:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = Z_OBJCE_P(object);
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:188:5: error: no member named 'scope' in 'struct _zend_executor_globals'
        EG(scope) = scope;
        ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:198:31: error: no member named 'scope' in 'struct _zend_executor_globals'
        zend_class_entry *scope = EG(scope);
                                  ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:204:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = seek;
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:216:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = info->ce;
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:218:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = ce;
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:221:41: error: no member named 'scope' in 'struct _zend_executor_globals'
        prop = zend_std_get_static_property(EG(scope), property, 1);
                                            ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:222:5: error: no member named 'scope' in 'struct _zend_executor_globals'
        EG(scope) = scope;
        ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:233:31: error: no member named 'scope' in 'struct _zend_executor_globals'
        zend_class_entry *scope = EG(scope);
                                  ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:239:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = seek;
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
/private/tmp/pear/temp/uopz/src/class.c:251:6: error: no member named 'scope' in 'struct _zend_executor_globals'
                EG(scope) = info->ce;
                ~~~^~~~~~
/Applications/XAMPP/xamppfiles/include/php/Zend/zend_globals_macros.h:46:34: note: expanded from macro 'EG'
# define EG(v) (executor_globals.v)
                ~~~~~~~~~~~~~~~~ ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [src/class.lo] Error 1
ERROR: `make' failed

call_user_func() ignores uopz_set_return hooks

If a hook is set via uopz_set_return() it is called when the function is called directly or as variable function as desired. However, calling the function via call_user_func() circumvents the hook, and calls the original function instead.

Reproduce code:

function foo() {echo 1;}
uopz_set_return('foo', function () {echo 2;}, true);
foo(); // => 2 
$f = 'foo';
$f(); // => 2
call_user_func('foo'); // => 1

Crash on module shutdown

Hi,

I'm experiencing a crash in uopz with php 5.4.28 & uopz 2.0.4.
Basically I'm just adding uopz.so without calling any uopz function, and it crashes :

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x000000010399e283 in _zend_mm_free_int ()
(gdb) bt
#0 0x000000010399e283 in _zend_mm_free_int ()
#1 0x00000001039b5715 in destroy_op_array ()
#2 0x00000001039c9be5 in zend_hash_apply_deleter ()
#3 0x00000001039c9cde in zend_hash_apply ()
#4 0x000000010272e717 in php_uopz_clean_user_class ()
#5 0x00000001039c9cc4 in zend_hash_apply ()
#6 0x000000010272e419 in zm_deactivate_uopz ()
#7 0x00000001039c4742 in zend_deactivate_modules ()
#8 0x000000010396b36c in php_request_shutdown ()
#9 0x0000000103a42bc2 in php_handler ()
#10 0x0000000100002e17 in ap_run_handler ()
#11 0x0000000100003281 in ap_invoke_handler ()
#12 0x00000001000203b6 in ap_process_request ()
#13 0x000000010001dda5 in ap_process_http_connection ()
#14 0x000000010000e107 in ap_run_process_connection ()
#15 0x0000000100025d11 in child_main ()
#16 0x0000000100025339 in make_child ()
#17 0x0000000100024aa2 in ap_mpm_run ()
#18 0x0000000100007d98 in main ()

I'll try to run it on a debug build to have more infos.

Thanks and regards,
Jocelyn Fournier

uopz_set_mock hangs when using an anonymous class as mock

When uopz_set_mock is called with an anonymous class as the mock, attempting to instantiate that class with an argument to the constructor causes the process to hang.

Minimal reproduction:

<?php
class X {}
uopz_set_mock(X::class, new class { public function __construct() {} });
$x = new X(0);

Installation details:

$ php -v
PHP 7.1.10 (cli) (built: Oct 10 2017 16:51:19) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.10, Copyright (c) 1999-2017, by Zend Technologies
with test_helpers v1.0.1-dev, Copyright (c) 2009-2013, by Johannes Schlueter, Scott MacVicar, Sebastian Bergmann
$ php --ri uopz

uopz

uopz support => enabled
Version => 5.0.2

I cannot reproduce this with xdebug on, but I assume that is actually just issue #61.

phpmd breaks once uopz.overload=1 is set

If the uopz is installed and uopz.overloads = 1 is configured, phpmd breaks:

[vinai@Sayyadina:/usr/local/etc/php/5.6/conf.d on master]
% cat ext-uopz.ini
[uopz]
zend_extension="/usr/local/opt/php56-uopz/uopz.so"
uopz.overloads = 1
[vinai@Sayyadina:/usr/local/etc/php/5.6/conf.d on master]
% php --version
PHP 5.6.9 (cli) (built: May 15 2015 09:36:14)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with uopz v2.0.7, Copyright (c) 2014, by Joe Watkins <[email protected]>
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans
[vinai@Sayyadina:/usr/local/etc/php/5.6/conf.d on master]
% phpmd --version                                                                                                                              127 ↵
PHPMD 2.2.2
PHP Fatal error:  Invalid opcode 65/4/8. in /usr/local/bin/phpmd on line 0
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phpmd:0

Fatal error: Invalid opcode 65/4/8. in /usr/local/bin/phpmd on line 0

Call Stack:
    0.0003    2074240   1. {main}() /usr/local/bin/phpmd:0

Once uopz.overloads is not set (or the uopz extension is removed completely) phpmd works fine.
The same behavior can also be found in php 5.5.25.

Do you have any idea what in phpmd might cause this issue or how to work around it? I would really like to use both phpmd and uopz.overload in CI.

Since I don't know if this or phpmd is a better repository to report the issue I've cross posted here: phpmd/phpmd#284

Handle to the original function/method?

Use case:

uopz_set_return(Foo::CLASS, 'myMethod', function(...$args){
    echo "entering myMethod with args:\n"
    print_r($args);

    // $_ is an handle to the "decorated" method/function
    // basically the original Foo::myMethod
    $result = $_(...$args);

    echo "leaving myMethod with return:\n";
    print_r($result);

    return $result;
}, true) : bool;

Would this be possible?
Thanks.

Breaking PHPRedis connect

Hi,

I am simply trying to grab the params used in the method of the Redis class.

Here is my code:

        uopz_backup('Redis', 'connect');
        $redisConnect = uopz_copy('Redis', 'connect');

        uopz_function('Redis', 'connect', function($ip, $port, $timeout, $a, $b) use ($redisConnect)
        {
            var_dump('================================================');
            var_dump('================================================');
            var_dump('================================================');
            var_dump($ip);
            var_dump($port);
            var_dump($timeout);
            var_dump($redisConnect($ip, $port, $timeout, $a, $b));
            var_dump('================================================');
            var_dump('================================================');
            var_dump('================================================');

            return $redisConnect($ip, $port, $timeout, $a, $b);
        });

I tried this code without uopz_backup function. But it did not change anything.

Here is the first error I get. It seems it is the uopz_copy function that is throwing it.

Warning: Cannot bind function Redis::connect to object of class Mindray_Core_Hooks

The following error I get is this:

Fatal error: Uncaught exception 'DataProvider_Exception' with message 'All servers timed out'

So clearly using this code causes the PHPRedis to not connect. When I take out the code everything is fine. So it is this code that is the source of the problem.

What am I doing wrong?

Thanks in advance for any help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.