Error on line 0 (zero)? How can this?

Asked

Viewed 1,114 times

4

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

Undefined index 'a' in line 5

But there are times when error is returned on line 0 (zero).

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 line count of the script starts from the 1 and not of 0

Example:

 <?= __LINE__ ?> // Retorna 1

Why PHP sometimes returns Erro in Line 0? Is it a bug? Or does it have logical explanation?

  • Hello friend, please it would be easier to help you if you put your codes so we can see where possibly this mistake.

  • Take a look at the second example

  • I don’t care about a specific mistake. I actually want to know where is this so-called line 0.

  • 1

    Converting errors into exceptions can help (I caught from here). My experience with scripting languages is that sometimes the engine gives an error on something you are pulling from another file, and then it fails to get the reference to the exact point where the error occurred and indicates zero line. I don’t know if PHP pre-compiles more if doing this is another indication that it might be something like.

  • Who gave the negative, could at least do the kindness to leave a feedback there, to see what can be arranged in the question.

  • 1

    Usually when it makes use of call_user_function(), eval(), overload, and things like that make the flow of the code obscure. The interpreter cannot get the line from which the interruption or the notice error originated. But I can’t say it’s that for your specific case. And of course, I’m not saying it’s bad to use the functions mentioned. Try to give a debug_backtrace() and goes in the race even sticking breakpoints by the codes. And shares with us what has found heheh

Show 1 more comment

3 answers

8


Taking a look at the sources of the PHP interpreter, 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 show 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 removed from the function php_error_cb main. c file of the interpreter)

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

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

There are, however, specific situations where this value cannot be obtained. And so we use a default value, 0, which results in the message you described.

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

0

your mistake is more or less 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/revisionmudanca.php' (include_path='.;C: xampp php PEAR') in Unknown on line 0

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

This may be your mistake, the name of action should be the same name of the php file that will be released the data.

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

-4

Something similar has happened to me, see if in the first line where you open the PHP tag there is no space:

espaço aqui<?php ?>

<?php ?> <-- deve ficar assim

Browser other questions tagged

You are not signed in. Login or sign up in order to post.