Implementing strict types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am looking at implementing something roughly equivalent to strict
typing for a part of my code.
Has anybody else had a go at such a thing?

I have some data types which I'm implementing as classes (base types
like "int" but also more specific types like "country") and I'd like
to be able to use them as normal variables (as far as assigning and
retrieving it's value goes) with 'magic' happening inside the class
for validation and normalisation (eg accepting any ISO style country
code on assignment but standardising on alpha 2 on output).

I am aware of the capability to override the assignment operator for a
property of an object, ie use the __set() magic method so that
====
$object->var='hello';
====
is equivalent to:
====
$object->__set('var','hello');
====
allowing the __set() method to do some funky stuff.

Is there a similar capability to override the assignment operator on
the object itself, ie have:
====
$object='hello';
====
handled by a method on the $object?

Similarly the __toString() magic method would cover part of the
"getter" overriding, but it seems to be a special case override that
only works within specific string functions rather than a generic
getter override.

Paul

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux