[KLUG Programming] PHP arrays vs. structures
Adam Tauno WIlliams
adam at morrison-ind.com
Tue Jul 20 09:47:42 EDT 2004
> >But other languages (C, etc...) as well as documents (XML, etc...) do
> >clearly distinguish between an array and a structure.
> Yes, and these are (in general) langauges that have much stronger roles
> for data types and distinct data structures than PHP has exhibited his-
> torically.
Yep, it is the moving of data too-and-fro between strictly-types and
loosely-types environments that is fraught with pitfalls. And XML falls
somewhere in between, as it is only a representation - but making
certain the representations gets interpreted the same way on both ends -
Yikes. XML-RPC is nice for quick-n-dirty, but for large or complex data
types its keep-it-simple-stupid ideology sort of sucks.
The OGo developers are adding SOAP invocation to the application engine,
but for now I'm stuck with XML-RPC.
I can also use WebDAV, if anyone knows of a good WebDAV client class
(with some half-way decen documentation) for PHP, I'd appreciate that.
Pointers to iCal & vCard parsers too - those are definitely things I
DON'T want to write.
> A C structure is a very different entity (at the lowest level) than a
> C array. I'm not at all convinced that this is the case for PHP (I have
> not looked at PHP 5 yet, so my commments do not address this. However, since
> PHP has been around for years, and PHP5 has been around for some days (in
> production form), this is most probably not obsolete information.
PHP5 seems to implement arrays/structures the same way. But it does
start to approach real object-orientation, and someday the SOAP
functionality will rescue me from much of this.
> Note especially the rols of the functions (primitives, or user-defined?) like
> <traceMessage>
traceMessage is mine, buried in the root parent of all the classes,
this helps make up for PHP laughable debugging and error handling
capabilities.
PHP5 is supposed to address this issue.
> and <gettype>, then consider what XML_RPC_value (or ANY such
> entity passed to <new>. Finally, note the recursive nature of this function,
> which is natural to any language which employs nested arrays or other essen-
> tially recursive data structures.
> > case 'array':
> > $this->traceMessage('@OGoDocument:wrap.array');
> > $a = array();
> > reset($value);
> > if (key($value) == '0') {
> > //array
> > $this->traceMessage('@OGoDocument:wrap.array.array');
> > $a_type = 'array';
> > foreach ($value as $v)
> > array_push($a, $this->wrap($v));
> > } else {
> > //struct
> > $this->traceMessage('@OGoDocument:wrap.struct');
> > $a_type = 'struct';
> > foreach ($value as $k => $v)
> > $a[$k] = $this->wrap($v);
> > }
> > $value = new XML_RPC_value($a, $a_type);
> > break;
> >... which seems to be able to turn PHP structures into documents that
> >can be transported to a web service.
> I don't see why not. Are you attempting such?
It does, thats why I wrote it. Or it seems to work so far.
More information about the Programming
mailing list