php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30090 Outside interface method can be called inside method that using the interface
Submitted: 2004-09-15 07:53 UTC Modified: 2004-09-15 08:07 UTC
From: mikarento at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.0 OS: Windows 2000
Private report: No CVE-ID: None
 [2004-09-15 07:53 UTC] mikarento at hotmail dot com
Description:
------------
Method who's parameter is object of particular interface should not invoke other method of its interface. 

Reproduce code:
---------------
interface Printable{
 public function print();
}

interface Writeable{
 public function write($text);
}

class ImplClass implements Printable, Writeable{
 public function print(){
  return 'hallo'
 }
 public function write($text){
  //...
  echo 'written';
 }
}

class Printer {
 public static function printIt(Printable p){
  p->write('wow');
 }
}

$a = new ImplClass();
Printer::printIt($a);

// the result is 'written'

Expected result:
----------------
error: Printable object doesn't have 'write' method 

Actual result:
--------------
written

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-15 08:07 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The object you pass is a ImplClass which has a write method. Your problem here is that PHP does only dynamic binding and resolving at runtime unlike for example C++.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Mar 02 14:01:23 2021 UTC