Why is this class in PHP working so weirdly with interface? [closed]

101
February 05, 2022, at 11:00 AM
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed yesterday.

This post was edited and submitted for review 23 hours ago.

Improve this question

I am new to PHP and am learning it. While I was going through this term called interface, I encountered into a weird output. I expected the result to be in the sequence 1,2,3,4 but the sequence of output is 2,3,4,1. I have used numbering to show it. The output is something like this:-

Here is the code:-

<?php
    interface Parent1{
        function sub($a, $b, $c);
    }
    interface Parent2{
        function add($a, $b);
    }
    class Calc implements Parent1, Parent2{
        function sub($a, $b, $from = 1){
            if($from == 1){
                return $a - $b;
            }elseif($from == 2){
                return $b - $a;
            }else{
                return "Please enter a valid value";
            }
        }
        function add($a, $b){
            return $a + $b;
        }
    }
    $calc = new Calc();
    echo "1." . $calc->sub(5, 3, 2) . "<br>";
    echo "2. " . $calc->sub(5, 3) . "<br>";
    echo "3. " . $calc->sub(5, 3, 3) . "<br>";
    echo "4. " . $calc->add(5, 3). "<br>";
    
?>

Is there any expert out there to modify the code to get the desired output. And why is it not giving result in the desired sequence?

Rent Charter Buses Company
READ ALSO
What is a Python Flask alternative to a JS &quot;onclick&quot; script?

What is a Python Flask alternative to a JS "onclick" script?

I want to make a Flask application for a puzzleUser should find some elements on a picture and click on them

105
React Native deep linking not working on React Navigation V6

React Native deep linking not working on React Navigation V6

When I configure my links and url-scheme with react navigation it falls into the fallback errorDon't know why

127
AdMob Android Banner Ads in component UI

AdMob Android Banner Ads in component UI

How to add AdMob Android Banner Ads in component UI

145
Bootstrap side bar collapse icon overlapping

Bootstrap side bar collapse icon overlapping

I am trying to fix a CSS issueso far it is not working

112