Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7754127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:13:49+00:00 2026-06-01T12:13:49+00:00

I have two PHP apps which have twho class with the same name. –

  • 0

I have two PHP apps which have twho class with the same name.
– app1 with a class “Project”
– app2 with a class “Project”

I have to use classes of the first app in the second one, but two class with one name cause an error (“PHP Fatal error: Cannot redeclare class Project …”).

I can’t change class names.
I have to use PHP 5.2 (no namespace in PHP 5.2).

Is there a solution ?

May be :

  • use the class Project
  • undef this class (kind of “unset Project”, is it possible with PHP ?)
  • include() the 2nd class
  • use the 2nd class

I don’t know if it’s possible with PHP (don’t find any ressource about this) and I don’t know a better way to manage this …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:13:50+00:00Added an answer on June 1, 2026 at 12:13 pm

    I had this problem recently, with (embarrassingly) Joomla. I needed to find the versions of two different installations with one script, by loading up their two “version.php” files and then reading the class properties. But, of course, they’re both called “JVersion”, and it’s impossible to require() both version.php files because of it.

    After much thought, I realized eval() could take the place of require(). So I just read in the contents of the version.php files and change the names of the classes, then eval() that text, and then I can access both classes with different names. I bet you’d like some code. Here’s what I ended up with…

    
    
        $v15_txt=file_get_contents($old_dir.'/libraries/joomla/version.php');
        $v15_txt=preg_replace('/class JVersion/i', 'class JVersion15', $v15_txt);
        eval('?>'.$v15_txt);
        $jvold=new JVersion15;
        $old_version = $jvold->RELEASE.'.'.$jvold->DEV_LEVEL;
    
        $v25_txt=file_get_contents($new_dir.'/libraries/cms/version/version.php');
        $v25_txt=preg_replace('/class JVersion/i', 'class JVersion25', $v25_txt);
        eval('?>'.$v25_txt);
        $jvnew=new JVersion25;
        $new_version = $jvnew->RELEASE.'.'.$jvnew->DEV_LEVEL;
    
    
    

    Just modify it so it loads the right two files for your needs and renames them as required. Sorry you had to wait over a year for it. 🙂

    It’s hard to believe PHP doesn’t have some kind of “undeclare($classname)” function built-in. I couldn’t even solve this with namespacing, because that requires changing the original two files. Sometimes ya just gotta think outside the framework.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes in a PHP application, B extending A for example. Class
I have two php files in the same directory: test.tattler.php class.tattler_stats.php My test.tattler is
I have two .php files which show all contacts in a database, then allows
I have two pages name one.php and two.php in one.php i have a combo
i have two php applications in my local wamp server. both applications use the
I have two PHP web applications. All of the apps are located on the
I have two PHP scripts, both using the same session by calling session_name('MySessID') .
I want to compare version numbers of apps/software which sometimes may have two decimal
I have two PHP arrays. One contains a group name and another contains a
I have two php database apps on different servers. I would like to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.