Page 1 of 1

dumbest question

Posted: Thu Dec 25, 2003 7:57 am
by elizabeta
hi,

i'm brand brand brand new in php and trying to learn some basics. like a good girl, i started with reading the manual - and as soon as i got to strings - i gut stuck ... :oops:

the dubmest question is: what is the function of: " ->"

i got to the code sample that has the following:

class foo
{
var $foo;
var $bar;

function foo()
{
$this->foo = 'Foo';
$this->bar = array('Bar1', 'Bar2', 'Bar3');
}
}

$foo = new foo();
$name = 'MyName';

echo <<<EOT
My name is "$name". I am printing some $foo->foo.
Now, I am printing some {$foo->bar[1]}.
This should print a capital 'A': \x41
EOT;
?>

so i'm guessing that -> assigns the value to the variable, or has a function like "cout" in C++, but i don't understand what "$this->" means??? if i'm guessing right about the funcitionality of "->" than what is "$this" :oops:

Posted: Thu Dec 25, 2003 8:05 am
by Weirdan
-> is member access operator. It's used to acccess the methods and properties of the object.
http://www.php.net/manual/en/language.oop.php
'$this' is 'magic' variable. It references 'current object'.

Posted: Thu Dec 25, 2003 8:19 am
by elizabeta
thanks

Posted: Thu Dec 25, 2003 10:50 am
by aquila125
Skip the OO part of PHP.. get back to it when you know the rest.. PErhaps it's better to check out a tutorial or two about normal scripting..

(OO isn't implemented very well in the current version of PHP... hopefully PHP5 will be beter)

Posted: Thu Dec 25, 2003 11:03 am
by Nay
Yeah, I was thinking that too. A tip to elizabeta, I'm sure most of us will agree with this too if you're ' brand brand brand new in php' as you said you are, learn some easier things about PHP. Sure OOP is quite simple as it may seem here but it's meant for more complex things and when using it for simple things - debugging is a pain.

Anyhow, like you said you wanted to learn the 'basics of PHP', well this isn't really the basics imho. It's more like the basics of more advanced PHP. Kill me if I don't make any sense btw :).

Hope that helped,

-Nay

Posted: Fri Dec 26, 2003 6:45 pm
by elizabeta
I agree with you 100 % but this is an example they used very early, talking about strings ... just a bad timing on them to set an example like that with no explanation at all ...

thanks for replies ... feel less dumb :)

Posted: Fri Dec 26, 2003 7:55 pm
by McGruff
aquila125 wrote:(OO isn't implemented very well in the current version of PHP... hopefully PHP5 will be beter)
Can't let that one go :) PHP4 is actually a very capable language for OOP - I'd be lost without it.

But, as you say, learn the vocabulary first before you start trying to write "literature". Don't think of OOP as hard though - in fact it makes things beautifully simple.