dumbest question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
elizabeta
Forum Newbie
Posts: 3
Joined: Thu Dec 25, 2003 7:57 am

dumbest question

Post 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:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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'.
elizabeta
Forum Newbie
Posts: 3
Joined: Thu Dec 25, 2003 7:57 am

Post by elizabeta »

thanks
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post 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)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
elizabeta
Forum Newbie
Posts: 3
Joined: Thu Dec 25, 2003 7:57 am

Post 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 :)
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Post Reply