Posted by Colin McKinnon on 04/14/06 20:15
Wescotte wrote:
> I have an application that uses several file formats for similar data.
> So I've created various php files for each format containing the same
> functions which produce the same end result.
>
<snip>
>
> The problem I'm running into is duplicate function names. Here is a
> test case of what exactly I was attempting to do. Anyone know how to
> actually get this to work?
>
> Output:
> Test1
> Fatal error: Cannot redeclare test_case() (previously declared in
> C:\Inetpub\Accounting\test1.php:5) in C:\Inetpub\Accounting\test2.php
> on line 6
Sorry Wescotte - while many people bemoan the lack of namespaces in PHP,
really this is just sloppy programming. If you are applying a procedural
methodology then you should be planning your program better - while you
might have deliberately chosen the same naming strategy for different the
functions in different include files - there's something wrong if it's
including more than one. In fairness, this is a very common mistake, and
one of the reasons for object oriented programming (which obviates such
eventualities).
So I guess the solutions are:
1) look at your flow of control - only include one file
2) or learn OO.
C.
Navigation:
[Reply to this message]
|