0

stupid question I know, but I need fresh eyes as I cannot see the error.

My code is this :

$element = $this->domDocument->getElementByTagName("Team");
        for ($i =0 ; $i < $element.length ; $i ++ ) {
        print $element[$i].childNodes[0].nodeValue;
        }

and the error is :

PHP Parse error:  syntax error, unexpected '['  on line 40

which is the line with the print statement.

Can you spot what is wrong?

ghostrider
  • 5,131
  • 14
  • 72
  • 120
  • 1
    $element.length should be $element->length – Sander Visser Sep 12 '14 at 11:53
  • 1
    I see too many questions like this. Take the time to learn how to [interpret errors and fix your code](http://jason.pureconcepts.net/2013/05/fixing-php-errors/). – Jason McCreary Sep 12 '14 at 11:53
  • 1
    If you are posting about a specific error you **must** include the full error message (with line number) and at least the code on that line and the line before it. – Jason McCreary Sep 12 '14 at 11:53
  • 1
    and it is `getElement**s**ByTagName` if you want to iterate ... – davidkonrad Sep 12 '14 at 11:54
  • @JasonMcCreary I have included everything. Line 40 is the line with the print statement, you can see the previous lines as well, and this is the full error message. Please re-read the questions. Thanks for the link, though. – ghostrider Sep 12 '14 at 11:57

2 Answers2

3
$element = $this->domDocument->getElementsByTagName("Team");
for ($i =0 ; $i < $element->length ; $i ++ ) {
    print $element[$i]->childNodes[0]->nodeValue;
}

I guess you're mixing up multiple languages ;)

Sander Visser
  • 4,144
  • 1
  • 31
  • 42
  • 1
    +1, _I guess you're mixing up multiple languages_ - probably thats why it was so hard to spot the syntax errors :) – davidkonrad Sep 12 '14 at 11:59
2

PHP does not use dot notation for objects, instead it uses an object operator (arrow).

$element = $this->domDocument->getElementsByTagName("Team");
for ($i =0 ; $i < $element->length ; $i ++ ) {
    print $element[$i]->childNodes[0]->nodeValue;
}
Community
  • 1
  • 1
Jason McCreary
  • 71,546
  • 23
  • 135
  • 174