Vebers Posted October 2, 2006 Report Posted October 2, 2006 Ir iespējams caur klasi izveidot pašā klasē jaunu memberi (mainīgo) caur metodi (funkciju) ? Ideāls piemērs būtu SimpleXML.
Delfins Posted October 2, 2006 Report Posted October 2, 2006 kas attiecās uz PHP, tu vari veidot cik vien vēlies memberu... nav strikta valoda. $x->aa = 1; vai $x->newAaa(); { $name = 'mans_aa_'.$this->aaaCount; $this->$name = 1; $this->aaaCount++; }
Vebers Posted October 2, 2006 Author Report Posted October 2, 2006 Nē, šķiet ka nesaprati. SimpleXML ir tā, ka ielasot XML failu automātiski klasē izveidojas memberi. piem., ja XML faila saturs ir: <?xml version='1.0' standalone='yes'?> <movies> <movie> <title>PHP: Behind the Parser</title> <characters> <character> <name>Ms. Coder</name> <actor>Onlivia Actora</actor> </character> <character> <name>Mr. Coder</name> <actor>El ActÓr</actor> </character> </characters> <plot> So, this language. It's like, a programming language. Or is it a scripting language? All is revealed in this thrilling horror spoof of a documentary. </plot> <rating type="thumbs">7</rating> <rating type="stars">5</rating> </movie> </movies> Un kā tas izskatās: echo $xml->movie[0]->title Ideja skaidra ?
bubu Posted October 2, 2006 Report Posted October 2, 2006 manuālīti vajag palasīties.. $a = "blah"; $$a = "xxx"; echo $blah;
Kaitnieks Posted October 2, 2006 Report Posted October 2, 2006 $this->movie = new xmlmember(); vai $this->$paramname = new xmlmember(); un ģenerē propertijus dinamiski. tipa tā?
Recommended Posts