ID:               47301
 Updated by:       johan...@php.net
 Reported By:      jevgeni at geimanen dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: Any
 PHP Version:      5.3.0beta1
 New Comment:

$a->intVar = 12 is overwriting the old intVar property, keeping the old
value would be a major beak to the way PHP works.


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

[2009-02-04 11:00:07] jevgeni at geimanen dot com

Description:
------------
It's a feature request for a new magic method named __setValue (could
be other more suitable name)

There is already magic method named __set, which is called when
inaccessible MEMBER is called. The one I propose should be called when
Object is called, receive the value that this object is being set to,
and return new value. For example:

class Int32 {
 function __setValue($value) {
   if (!is_int($value)) throw new Exception("Type checking...");
   return $value;
 }
}
class A {
 public $intVar;
 public function __construct() {
  $this->intVar = new Int32();
 }
}
$a = new A();
$a->intVar = 12; //is ok
$a->intVar = "asdf"; //throws exception

That feature would give TONES of new possibilities, type checking is
one of them.



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


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

Reply via email to