Log in

No account? Create an account
Ramblings Journals I Read Calendar The Dirt MegaZone's Waste of Time Older Older Newer Newer
gronk - MegaZone's Safety Valve
The Ramblings of a Damaged Mind
Learning a programming language under the gun isn't my favorite way of doing it. I like to have more time to read the PHP docs, but time is what I don't have. So I bulldoze on ahead, looking up answers when necessary. But I can't help but feel that I'm missing the bigger picture - the language structures, etc. Tonight I floundered about a bit figuring out XML DOM parsing with XPath in PHP. Turned out to be a lot easier than I thought - my first impression, from the docs, was that the XML DOM extension didn't do XPath! Just incomplete docs - I only just discovered that the online HTML version of the docs includes user submitted comments, which clear up a hell of a lot really. (I'd be using the PDF version of the docs that I downloaded.)

Still, it appears that you can't do things in one step in PHP that you can in Perl. For example:
$xpath = "//CurrencyTable/CurrencyShift[\@number='" . $currencyNumber . "']";

if (($domCurrency->findnodes($xpath))[0]->hasAttribute("name")) {

For PHP you have to break that statement down:
$test = $domCurrency->get_elements_by_tagname($xpath);
if ($test[0]->has_attribute("name")) {

PHP isn't happy if I try something like
if ($domCurrency->get_elements_by_tagname($xpath)[0]->has_attribute("name")) {

Please, correct me if I'm wrong. :-) It just seems like it doesn't allow you to directly reference an element from a method that returns an array.

I am: tired tired
Current Media: quiet

donnerjack From: donnerjack Date: September 3rd, 2003 11:09 pm (UTC) (Direct Link)
Hrm, I think you should be able to do that, but I'm honestly not positive. The look of that statement is a bit off, so there may be a syntactic trick to get it to deal with it. The user submitted comments in the online PHP docs are the shit. They clarify so much stuff and add so much crap that's missing in the actual docs, it's wonderful. And they're a great source of example code.
From: twistedraisin Date: September 4th, 2003 10:55 am (UTC) (Direct Link)
you might try:
if ($domCurrency->{get_elements_by_tagname($xpath)}[0]->has_attribute("name"))

...php can be syntactically finicky sometime. Okay, alot of the time.
zonereyrie From: zonereyrie Date: September 4th, 2003 02:58 pm (UTC) (Direct Link)
Ah - Looking at the Zend2 changes it looks like I'm SOL with PHP4/Zend system. 'In PHP 4 it wasn't possible...' pretty much says it all. ;-)

In http://www.php.net/zend-engine-2.php
Dereferencing objects returned from functions

In PHP 4 it wasn't possible to dereference objects returned by functions and make further method calls on those objects. With the advent of Zend Engine 2, the following is now possible:

class Circle {
function draw() {
print "Circle\n";

class Square {
function draw() {
print "Square\n";

function ShapeFactoryMethod($shape) {
switch ($shape) {
case "Circle":
return new Circle();
case "Square":
return new Square();