php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #19411 Pre-existing classes defined WHERE?
Submitted: 2002-09-14 22:13 UTC Modified: 2004-01-17 10:25 UTC
From: ceo at l-i-e dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.2.2 OS: All
Private report: No CVE-ID: None
 [2002-09-14 22:13 UTC] ceo at l-i-e dot com
It would be Really Nifty (tm) if the class system would tell 
me *WHERE* somebody has already defined "class foo" when it 
won't let me create class foo because it already exists.

Some bozo is making me use "class User" (how original) but 
I've got no idea where the *other* class User is and which 
one will be less hassle to change, and PHP ain't telling :-(

I hate inexperienced OO programmers.  They cause more 
problems than if we just made them not use OO in the first 
p

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-17 21:12 UTC] yohgaki@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.


 [2002-09-17 22:26 UTC] ceo at l-i-e dot com
It's a FEATURE REQUEST, not a support question.

Currently, PHP's error message when encountering:

class foo {

the SECOND time simply tells me it's "already defined".

While that would be useful if I was, say, including the same 
file twice, it's not particularly  useful when trying to 
integrate two (or more) object-oriented 3rd-party libraries.

The error message would be infinitely more useful if it 
included the __FILE__ and __LINE__ of the first:
class foo {

This is essentially the same problem/solution as the old 
"headers already sent" problem, which now explicitly states 
which line/file caused the original out
 [2002-09-17 23:41 UTC] wez@php.net
The engine can't always guarantee to be able to know
exactly where the class was defined.
For instance, the class might be an internal class (like
the Directory class) defined by an extension, or it might have been generated by an eval statement.

The definition location should be fairly easy to
store/recall - just add a field to zend_class_entry,
and tweak the parser so that the error message is more
meaningful.  I'll forward this on to some other developers
and we'll see what comes up.

Until this is implemented, you can use something like
this from your unix/cygwin shell prompt:
grep -ni 'class User' $(find -name '*.php')

 [2004-01-10 12:08 UTC] php at thekid dot de
The Reflection API in PHP5 can tell you where a class was defined. 

See http://www.sitten-polizei.de/php/reflection_api/docs/language.reflection.class.reflection_class.html for details.
 [2004-01-17 10:25 UTC] andrey@php.net
So, with the Reflection API this is possible -> closing
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Aug 21 01:01:30 2024 UTC