On 1 March 2011 04:40, Paul McGarry <p...@paulmcgarry.com> wrote:
> 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
>
>

There is __invoke, but that is for ...

$instance()


The problem is (hopefully) explained in ...

$instance = 'something that needs to be passed to instance and not
assigned to instance';

How do you differentiate between the two "assignments" (one to the
variable and one to be processed by the instance) ?

Richard.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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

Reply via email to