1

I am working on a website with a few friends, and recently, users have complained about a fairly important feature doing nothing but return a blank page. This only happens for some users, while other users are able to use it perfectly fine.

I consulted debug output and it turns out that a function is being declared twice. Once in the feature's main page (foo.php) and one in a file that gets require_once'ed. Obviously I'm on the right path to fixing it now, but what confuses me is that many people do not get this problem when visiting the page. Both function declarations are identical; the bodies seem to have been copy+pasted from one file to the other. Neither of these function declarations are conditional; they should both always take place.

Does anybody know of situations where PHP will be able to handle my mistake and make the page work anyway, despite this fatal error?

Neko
  • 3,550
  • 7
  • 28
  • 34
  • first fix all with `require_once`, and depending on what pages are visited, there can be cases where a page has included a particular file once, or many times. – linuxeasy Apr 09 '12 at 12:34
  • As said in the post, I am already using require_once. – Neko Apr 09 '12 at 12:36
  • PHP doesn't allow function declaration more than once (with the same scope). Some visitors might think different and don't shout. – Riz Apr 09 '12 at 12:39
  • It might be worth looking into what is different about these users. There will be a reason it only happens to these people. It could be for example they are admins and a script only included if the person has relevant access etc. – Peter Apr 09 '12 at 12:43
  • I have tested it myself, dev. With my own account, it works fine. With a test account, it shows a blank page. – Neko Apr 09 '12 at 12:43
  • @dev: I assume that by *scope* you meant *namespace*? – netcoder Apr 09 '12 at 12:44
  • @Neko: It's probably your workflow that is different depending on the account and/or previous steps. PHP never allows function to be declared twice. Use a debugger with breakpoints, stack trace, etc. to find out. – netcoder Apr 09 '12 at 12:45
  • Are either of them using `function_exists()` to check before creating the function definition? – Mike B Apr 09 '12 at 12:46
  • If it is down to a flaw in the language that isn't documented, or a flaw in the understanding of the programmer, it is always the programmer that is wrong. Clearly, there is conditional logic you aren't aware of. Check for traditional if/switch stuff first, then look for `code or { code }` style ones. You'll find it. – DampeS8N Apr 09 '12 at 12:48

2 Answers2

1

it may be the type of your function declaration is public,private or protected so that you might be not getting fatal errors by luck as till to my knowledge php does not allow function redeclaration in or by any means .

Blackpearl
  • 11
  • 2
0

Sorry, PHP can never ignore fatal errors or function redeclarations, because in that cases, PHP will be confused as to what function declarations to consider, whether to use a old declaration or a new declaration.

  • Fatal Error means, there has something is so wrong, that PHP is confused as to what to do next, and therefore its your job to do it right.

  • Sorry PHP wont try to figure out as if two or more declarations were same and then ignore one of them. If this had to be done, the already slow PHP will become even more slower. So in the interest of community, you should consider writing a correct code, rather then asking PHP interpreter to correct this for you.

linuxeasy
  • 6,269
  • 7
  • 33
  • 40
  • 1
    I know this, and I am not asking for a way to make PHP solve my problem, as you can see in the original post. PHP **is** currently ignoring this fatal error in some circumstances, and I am trying to get to know why it does this. – Neko Apr 09 '12 at 12:43
  • You can easily get to know this by debugging in detail, and by checking error logs. its programming and anything can be programmed in anyway in programming! If its blank, means its an error, if you haven't already enabled error loging in file for php errors, you should consider doing it. – linuxeasy Apr 09 '12 at 12:45
  • @Neko: No it's not ignoring it. It can't. It's something else. – netcoder Apr 09 '12 at 12:47
  • @linuxeasy: I did enable error logs on the dev part of our website; it's how I found out that the function is being redeclared. For regular users, errors aren't showed, which results in an empty page. – Neko Apr 09 '12 at 13:14
  • I'm experiencing this too. PHP comes across a second declaration, internally treats it as an error, but does nothing else. Not actually ignoring, not complaining either. – Otheus May 22 '20 at 17:03