[suspicious - maybe spam] #32379 [Opn->Bgs]: type hinting doesn't inforce encapsulation

From: Date: Sat, 19 Mar 2005 23:55:06 +0000
Subject: [suspicious - maybe spam] #32379 [Opn->Bgs]: type hinting doesn't inforce encapsulation
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-75545@lists.php.net to get a copy of this message
 ID:               32379
 Updated by:       johannes@php.net
 Reported By:      freebsd at dds dot nl
-Status:           Open
+Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: FreeBSD
 PHP Version:      5.0.3
 New Comment:

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

Type hints don't check what you are doing with your object, 
they just help you to know what you have... 


Previous Comments:
------------------------------------------------------------------------

[2005-03-20 00:40:59] freebsd at dds dot nl

Description:
------------
Type hinting doesn't prevent you from calling functions of children
that are not defined in the interface or (abstract) class. This mean
you could call a function of object x, then create a new class (y) that
doesn't implement this function, resulting in an error later on.

Basicaly the principle of encapsulation (on class level) isn't
enforced.



Reproduce code:
---------------
<?php
  interface X {
    public function fa();
  }

  class Y implements X {
    public function fa() {}
    public function fb() { echo "no error / warning?"; }
  }

  function f(X $y) {
    $y->fb();
  }

  f(new Y()); 
?>


Expected result:
----------------
An error (or at least a warning).

Actual result:
--------------
n/a


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=32379&edit=1


Thread (6 messages)

« previous php.bugs (#75545) next »