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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mikarento at hotmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 03:01:28 2024 UTC