please keep replies on list.
Philip Thompson schreef:
> On Feb 19, 2009, at 2:59 AM, Jochem Maas wrote:
>
>> Philip Thompson schreef:
>>> Hi all.
>>
>> ....
>>
>>>
>>> What are your thoughts? Does this seem like a reasonable implementation?
>>> Useful? Pointless? Hit me up - I can handle *constructive* criticism.
>>> But for now, it's late and past my bedtime.
>>
>> how do you set a property to null?
>
> Oh sure, point that out! JK. I thought of that as well. For members
> where 'null' is an option, you may just want to create a definitive
> accessor or modify the __call() function. Use a string to represent null
> - I'll use 'nil' from objective-c. Something like this...
yes but then someone might want to set the value to 'nil' or '__nil'
or any other magic value you might want to use.
what about capturing a method name prefix:
$person->unsetFirst();
> <?php
> public function __call ($member, $args)
> {
> if (property_exists ('Person', $member)) {
> if (empty ($args)) {
> list ($value) = $this->$member;
> return $value;
> }
>
> // Test to see if value is 'nil'. If so, set to null.
> if (!is_array ($args[0]) && $args[0] == 'nil') {
> $args[0] = null;
> }
>
> $this->$member = $args;
> }
> else {
> die ("Fatal Error: Call to undefined member: $member. Exiting...");
> }
> }
>
> $person = new Person();
> $person->first('Billy');
> $person->first('nil');
> ?>
>
> I suppose it's a possibility that someone will assign 'nil' to a member
> as an actual value, so put in some more checking or modify the null
> keyword - maybe '__nil' or whatever? That a possibility?
>
> Cheers,
> ~Phil
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php