You are here: Problems with include and duplication function definitions « PHP Programming Language « IT news, forums, messages
Problems with include and duplication function definitions

Posted by Wescotte on 04/14/06 19:49

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.

Now I currently have a functions setup that just reads a file and
determines which file type it is and includes the correct source. My
goal is add a new function to each source called
My_File_Format($filename) where each file checks to see if the
specified file is the format it knows how to work with.

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

Assumed should be
Test1Test2

file testcase.php
<html>
<body>
<?php

class file_format
{
var $f;
function file_format($filename)
{
$this->f = $filename;
}
function is_format()
{
include "$this->f";
test_case();
}
}

$a = new file_format("test1.php");
$b = new file_format("test2.php");
$a->is_format();
$b->is_format();

return;


?>
</body>
</html>

file: test1.php
<?php

function test_case()
{
echo "Test1";
}
?>

file: test2.php
<?php

function test_case()
{
echo "Test2";
}
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация