Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does php continue interpreting after die(); [duplicate]

Possible Duplicate:
stop php processing file

Today while playing around with PHP a noticed a strange thing

I had a block of Code where it does a job.

$images = $wpdb->get_results($query);
    foreach($images as $image):
        $img = get_post($image->meta_value);
        print_r($img);
    endforeach;

And after this piece of code i tried to die; because i needed to analyse the output.

$images = $wpdb->get_results($query);

            foreach($images as $image):
                $img = get_post($image->meta_value);
                print_r($img);
            endforeach;
    die;bla bla bla qit error !98123

Which means stop by this line and dont go further.

But it goes and i thought as a Scripting Language it parses Line by Line and will not go after the die;

But in fact it goes.

Does some one has any explanation for that ?

like image 466
Rosmarine Popcorn Avatar asked Jul 25 '26 23:07

Rosmarine Popcorn


1 Answers

The die() and exit() functions only stop execution of the script, which happens only after the file has been fully parsed.

If you with to stop parsing itself, you must use __halt_compiler(), see: http://php.net/manual/en/function.halt-compiler.php

like image 120
Matteo Tassinari Avatar answered Jul 27 '26 14:07

Matteo Tassinari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!