ghostrider
ghostrider

Reputation: 5259

Syntax error on PHP - in need of fresh eyes

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?

Upvotes: 0

Views: 89

Answers (2)

Jason McCreary
Jason McCreary

Reputation: 72961

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;
}

Upvotes: 2

Sander Visser
Sander Visser

Reputation: 4320

$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 ;)

Upvotes: 3

Related Questions