Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception from ZEND_EXIT overload #17

Closed
Raven24 opened this issue Mar 9, 2015 · 4 comments
Closed

exception from ZEND_EXIT overload #17

Raven24 opened this issue Mar 9, 2015 · 4 comments

Comments

@Raven24
Copy link

Raven24 commented Mar 9, 2015

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?

@krakjoe
Copy link
Owner

krakjoe commented Mar 9, 2015

You can still throw an exception, nothing has changed in that regard.

<?php
class Unit {
    public function test() {
        exit(10);
    }
}

class Uopz_Test extends PHPUnit_Framework_TestCase
{
    public static function setupBeforeClass() {
        uopz_overload(ZEND_EXIT, function($status = 0) {
            throw new Exception("test");
        });
    }

    public function testExit()
    {
        $unit = new Unit();
        $unit->test();
        $this->assertTrue(true);
    }

    public static function teardownAfterClass() {
        uopz_overload(ZEND_EXIT, null);
    }
}
?>

This is fine, and still make sense.

When you throw, you are instructing the executor to leave the current block (scope), which is what you are doing when you return ZEND_USER_OPCODE_RETURN.

@krakjoe krakjoe closed this as completed Mar 9, 2015
@Raven24
Copy link
Author

Raven24 commented Mar 9, 2015

thanks for your quick response!
unfortunately I get a segfault when I try to run your code with

  • PHP 5.5.22 (cli) (built: Feb 19 2015 07:04:43)
  • with uopz v2.0.7 from PECL
  • PHPUnit 4.5.0

the output I get from strace right before the crash is:

open("/usr/local/bin/phpunit", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0775, st_size=3411356, ...}) = 0
lseek(3, 0, SEEK_CUR)                   = 0
lseek(3, 2662017, SEEK_SET)             = 2662017
read(3, "<?php\n/**\n * GlobalState\n *\n * C"..., 8192) = 8192
lseek(3, 2670209, SEEK_SET)             = 2670209
read(3, " foreach ($superGlobalArrays as "..., 8192) = 8192
lseek(3, 2673320, SEEK_SET)             = 2673320
brk(0)                                  = 0x7f79e5265000
brk(0x7f79e52a5000)                     = 0x7f79e52a5000
close(3)                                = 0
getcwd("/home/user/src/unittests", 4096) = 28
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x209} ---
+++ killed by SIGSEGV (core dumped) +++

let me know if you need any more information to debug this.

@krakjoe
Copy link
Owner

krakjoe commented Mar 9, 2015

with uopz v2.0.7 from PECL

These changes are only in master right now, and are tentative (unreleased)

@Raven24
Copy link
Author

Raven24 commented Mar 10, 2015

ok, thanks. I tried the code from git and it worked. the segfault was a problem somewhere in my setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants