Re: Objects as Arrays

From: Date: Fri, 19 Sep 2003 19:18:11 +0000
Subject: Re: Objects as Arrays
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-4533@lists.php.net to get a copy of this message
Hello, Friday, September 19, 2003, 9:08:10 PM, you wrote: > [...] the one question/concern i have with the patch is consistency > with the new read_dimension/write_dimension object handlers. seems like > it would have a bit of the WTF factor on the end user side if the > read_dimension handler and get_properties handlers return different > results. in other words, s/he can use array_* functions on the object, but > normal indexing may not work as expected. Well if you don't want array_*() function support for your objects then you can simply return NULL in get_properties() handler and voila. > as an example, i have a UnicodeString class which uses the dimension > handlers to return a Unicode codepoint at a given offset in the string. > this takes only numeric indices. in addition i have a "length" property > which is returned by the get_properties handler. > do you see a problem in this scenario ? or do we request extension writers > to support something like $myUnicodeString["length"] in the read_dimension > handler as a matter of consistency (i would hope not)? And if you want to have both array behaviour and properties that are not handled by array_*() functions then you can simply handle them in the read_dimension/write_dimension() handlers and store them aside from the standard properties hash table. On the contray my patch allows objects to wrap around arrays and behave like arrays. > Friday, September 19, 2003, 1:18:53 PM, you wrote: >> Hello internals, >> IIRC it was intended to use object properties as arrays. Currently most >> array_*() functions do explicitly check for IS_ARRAY. The patch below now >> enables objects in nearly all array_*() functions. The contray of such an >> approach is that it would allow to access/modify protected and private >> properties. But for some functions we do it already so we need to find a >> solution for that sooner or later independantly from this patch. >> Any thoughts? >> >> http://marcus-boerger.de/php/ext/standard/php-array-20030918.diff.txt >> -- >> Best regards, >> Marcus >> mailto:mail@marcus-boerger.de -- Best regards, Marcus mailto:helly@php.net

« previous php.internals (#4533) next »