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

No data received error in the browser when re-throwing the same caught exception in aop_add_after_throwing() and using getKindOfAdvice() inside the advice itself #92

Open
tonix-tuft opened this issue Mar 7, 2015 · 0 comments

Comments

@tonix-tuft
Copy link

Hi,

The following code:

<?php

aop_add_after_throwing("*->*()", function(AopJoinPoint $joinPoint) {
        echo "Inside advice";
        $e = $joinPoint->getException();

        var_dump($e);

        $type = $joinPoint->getKindOfAdvice();
        var_dump("TYPE: " . $type);                             
});

class RiskyClass {

    public function riskyInstanceOperation() {
        //*
        try 
            {
                // do something risky

                if (false) {
                    echo "succeeded";
                }
                else {
                    throw new Exception("Ooops!");
                }   
            }
        catch (Exception $e)
            {
                echo "Exception caught";
                throw new Exception("But another thrown");              
            }
        //*/
    }

}

$obj = (new RiskyClass())->riskyInstanceOperation();

Works like expected, outputs Inside advice, the var_dump of the exception and the type of the advice: string 'TYPE: 324'

However, instead of throwing new Exception("But another thrown"); if I re-throw the same caught exception:

<?php

aop_add_after_throwing("*->*()", function(AopJoinPoint $joinPoint) {
        echo "Inside advice";
        $e = $joinPoint->getException();

        var_dump($e);

        $type = $joinPoint->getKindOfAdvice();
        var_dump("TYPE: " . $type);                             
});

class RiskyClass {

    public function riskyInstanceOperation() {
        //*
        try 
            {
                // do something risky

                if (false) {
                    echo "succeeded";
                }
                else {
                    throw new Exception("Ooops!");
                }   
            }
        catch (Exception $e)
            {
                echo "Exception caught";                                
                throw $e; // re-throwing the same exception
            }
        //*/
    }

}

$obj = (new RiskyClass())->riskyInstanceOperation();

No output is given and instead the following error appears in the browser:

No data received

Unable to load the webpage because the server sent no data.
Error code: ERR_EMPTY_RESPONSE

Server response is empty.

I found that it is something that has to do with $joinPoint->getKindOfAdvice();, therefore when the getKindOfAdvice() method is called, because if I comment these lines:

$type = $joinPoint->getKindOfAdvice();
var_dump("TYPE: " . $type); 

Inside the advice's callback and I refresh the browser, everything works even with re-thrown exception.

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

1 participant