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 9312475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:38:23+00:00 2026-06-19T01:38:23+00:00

In the following script I declare two methods with the same name calculate but

  • 0

In the following script I declare two methods with the same name calculate but different signatures. But I get an error on declaration:
Fatal error: Cannot redeclare Tester::calculate() in /opt/lampp/htdocs/tester.php on line 7
. Why is that ? Php doesn’t support this type of polymorphism ?

<?php
class Tester {
    public function calculate() {
        echo 2*2;
    }

    public function calculate($var_1,$var_2) {
        echo $var_1*$var_2;
    }
}

$obj = new Tester();
$obj->calculate();
echo "<br />";
$obj->calculate(5,4);
  • 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-19T01:38:24+00:00Added an answer on June 19, 2026 at 1:38 am

    PHP != (Java, C++, C#, VB.Net)

    Although PHP borrows heavily from Java, there are some big differences between the two (and other OOP languages). One big one is you can’t have methods using the same names with different parameters. You either need to:

    • Use default argument variables
    • Use different methods names
    • Extend a parent/abstract class (a.k.a. inheritance) and then you can use polymorphism
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script which behaves differently on two different Perl installations I
Consider following script: SET LANGUAGE 'German' GO SET DATEFIRST 1 GO DECLARE @FullDate DATETIME
The following script works for me, but I wonder if it could be done
The following script creates symlinks as expected, but the original file can never be
The following script will update the database, but it won't display the correct page
When I executed the following script, I am getting the following error. What should
I have the following script that I want to insert into a table, but
Please copy and run following script DECLARE @Customers TABLE (CustomerId INT) DECLARE @Orders TABLE
I'm trying to get two pieces of information from the following cursor: 1. Subdomain
Please see/run the following script. DECLARE @Products Table ( PId int ) INSERT @Products

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.