3
$arrg = array();
if( str_word_count( $str ) > 1 ) {
    $input_arr = explode(' ', $str);
    die(print_r($input_arr));
    $count = count($input_arr);
    die($count);

above is part of a function. when i run i get;

Array (
    [0] => luke
    [1] => snowden
    [2] => create
    [3] => develop
    [4] => web
    [5] => applications
    [6] => sites
    [7] => alse
    [8] => dab
    [9] => hand
    [10] => design
    [11] => love
    [12] => helping
    [13] => business
    [14] => thrive
    [15] => latest
    [16] => industry
    [17] => developer
    [18] => act
    [19] => designs
    [20] => php
    [21] => mysql
    [22] => jquery
    [23] => ajax
    [24] => xhtml
    [25] => css
    [26] => de
    [27] => montfont
    [28] => award
    [29] => advanced
    [30] => programming
    [31] => taught
    [32] => development
    [33] => years
    [34] => experience
    [35] => topic
    [36] => fully
    [37] => qualified
    [38] => electrician
    [39] => city
    [40] => amp
    [41] => guilds
    [42] => level )

Which im expecting;

run this however and nothing is returned:

$arrg = array();
if( str_word_count( $str ) > 1 ) {
    $input_arr = explode(' ', $str);
    //die(print_r($input_arr));
    $count = count($input_arr);
    die($count);

6 Answers 6

11
die($count);

Kills your script with $count (an integer) as an exit code.

You'll want:

die((string) $count);

(Or comparable.)

Sign up to request clarification or add additional context in comments.

Comments

5

From http://www.php.net/manual/en/function.exit.php (same as die()):

If status is a string, this function prints the status just before exiting.

If status is an integer , that value will also be used as the exit status. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.

2 Comments

Arguably this is worded wrong, isn't it? "Will also be" should be "will be". :)
You should pass that on to the php documentation team, eh?
2

Hmm. Is it doing this because $count is an integer, I wonder? What happens if you die(strval($count))?

Comments

2

die() will not print the argument if it is numeric, it'll use it as exit status code instead.

The problem is only your debugging technique... :o)

Comments

1

have you tried to output $count? at the moment you kill your scrippt with $count as errorcode. simly do

die(print($count));

to get what you want.

1 Comment

This is actually a pretty neat solution, since print returns 1, so after printing, die(); still gets an error code to work with. Of course, this is debugging code, so it's not as useful as it could be, but the construct in general is worth keeping in mind. +1
0

Integer parameter to die is used as exit code of the process (die is equivalent to exit). Just check the documentation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.