首页 > 解决方案 > PHP 2 class implements interface

问题描述

Why the code didn't display a solution to object Ab. If i want display for object Ab i must add $Ab->a().

<?php

interface AB {

    public function a();
}

class A implements AB{

    public function a() {
        echo "aaaa";
    }

}

class B implements AB {

    public function a() {
        echo "bbbb";
    }

}

$Aa = new A;
$Ab = new B;

this code show only aaaa without bbbb. Why this work that? How to display both objects do nothing more?

标签: phpclassinterface

解决方案


推荐阅读