Error in line 0 (zero)? How can this be?

4

In PHP, when an error occurs, usually the line of the script where the same occurred is informed:

  

Undefined index 'a' in line 5

But there are times when error 0 is returned at line 0.

Example:

  

Fatal error: Call to a member function items () on a non-object in File.php on line 0

By the time I work with PHP, I know very well that the script count starts from 1 and not 0

Example:

 <?= __LINE__ ?> // Retorna 1

What is the reason PHP sometimes returns Erro in Line 0 ? Is it a bug? Or is this logical explanation?

    
asked by anonymous 12.05.2016 / 15:24

3 answers

8

Taking a look at the PHP interpreter sources, I came to some conclusions.

The PHP interpreter handles various types of errors (exceptions, warnings, deprecated warnings, etc.). The default behavior for most cases is to display a message as below:

fprintf(stderr, "%s: %s in %s on line %u\n", error_type_str, buffer, error_filename, error_lineno);

(This excerpt was taken from the php_error_cb function of the interpreter's main.c file)

The last parameter, error_lineno , is the most relevant in this case because it indicates the error line.

Where does this value come from? Without going into too much detail, the interpreter looks for the line of the program execution context, basically what PHP was executing at the time of the error.

There are, however, specific situations where this value can not be obtained. And therefore a default value of 0 is used which results in the message you have described.

In short, line "0" is not literally a line, it is a default value used by PHP when it does not "know" what the line is.

    
26.10.2016 / 16:03
0

Your error is something like this:

Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0 Fatal error: Unknown: Failed opening required 'C: \ xampp/htdocs/revisanomudanca.php' (include_path = '.; C: \ xampp \ php \ PEAR') in Unknown on line 0

So this happened to me too, so I checked action , where the data was going:

This may be your error, the name of the action should be the same name as the file in php that will be released.

Another possibility is that you have saved the file with some invalid character, such as ç or ~~, or any other accent, save the file name without any accent.

    
23.11.2017 / 14:32
-4

Something similar happened to me, see if the first line where you open the PHP tag does not have any space:

espaço aqui<?php ?>

<?php ?> <-- deve ficar assim
    
27.10.2016 / 11:37