Hi everybody,
A php newb here, with what I'm sure will seem like a ridiculously simple question but it's new to me so here goes. I've been a programmer for over 15 years, but I've never seen the following syntax in any other language. I don't really understand what it means.
Here is an example:
$x=$xmlDoc->getElementsByTagName('ARTIST');
Here's another:
$cd=($y->childNodes);
And another:
for ($i=0;$i<$cd->length;$i++)
That little bit that kind of looks like a cheap asciii attempt to make a rightwards pointing arrow, "->" what is that? Minus less than? It doesn't really make sense to me. I've checked dozens of online tutorials, websites, and fact sheets. Some use the syntax but none I've found actually explains it. They just present it and assume we know what it means. It's not that intuitive to me. I've worked in a lot of different languages in my career but none that uses this syntax. So it's not that intuitive to me. Maybe I'm just thick, or coming from a different angle than most. SQL Server, Javascript, VB. Never been much up on the C derivitivs. Maybe it's used there, but not in anything I've worked in.
Any help, greatly appreciated.
Thanks,
Phil
What is this syntax?
Moderator: General Moderators
Re: What is this syntax?
It's basic OOP (Object Oriented Programming)
The thing you see before the "->" is the object, and what comes after is what you're trying to fetch inside the object.
For instance $object->Names, here you're accessing the object called $object and trying to fetch the variable, funciton or likewise inside the object calles "Names".
If you're interested you could look more into OOP on the php website: http://dk.php.net/manual/en/language.oop5.php
The thing you see before the "->" is the object, and what comes after is what you're trying to fetch inside the object.
For instance $object->Names, here you're accessing the object called $object and trying to fetch the variable, funciton or likewise inside the object calles "Names".
If you're interested you could look more into OOP on the php website: http://dk.php.net/manual/en/language.oop5.php
Re: What is this syntax?
Sort of like dot notation then? For example in VB or javascript it would be object.property or object.method? So in PHP we do with with object->property using [->] instead of a [.]?
Re: What is this syntax?
Yes.pchika wrote:Sort of like dot notation then? For example in VB or javascript it would be object.property or object.method? So in PHP we do with with object->property using [->] instead of a [.]?
Re: What is this syntax?
Got it, makes perfect sense. Thanks to all!!
Re: What is this syntax?
Or like C++'s object pointersSort of like dot notation then? For example in VB or javascript it would be object.property or object.method?
Like:
Code: Select all
#include <iostream>
#include <conio.h>
using namespace std;
class foo
{
public:
void bar()
{
cout << "Hello world." << endl;
}
};
int main()
{
foo *foo;
foo->bar();
getch();
return 0;
}Code: Select all
<?php
class foo
{
public
function bar()
{
echo 'Hello world.';
}
}
$foo = new foo;
$foo->bar();
return 0;
?>