What are the -> and :: operators?

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
terminator24h
Forum Newbie
Posts: 4
Joined: Mon Mar 02, 2009 11:43 pm

What are the -> and :: operators?

Post by terminator24h »

Just took on a job managing a site with a PHP/MySQL backend. Very simple question that I can't solve for the life of me. What do the -> and :: operators do?

Here they are in context:

Example 1:

// populate $schedules->moveout and $schedules->movein for filter list

$schedules->moveout = admin_dataAdapter::get_schedules_all($adminuser->school_list,'moveout');
$schedules->movein = admin_dataAdapter::get_schedules_all($adminuser->school_list,'movein');

Example 2:

foreach($adminuser->school_list as $school)

My best guess is that -> points to an element of an array that's specified with a name?

Any help is much appreciated. Thank you for tolerating my n00bieness.
terminator24h
Forum Newbie
Posts: 4
Joined: Mon Mar 02, 2009 11:43 pm

Re: What are the -> and :: operators?

Post by terminator24h »

Of course, immediately after posting, I discovered that -> refers to a variable within an object:

$object->$var = 5;

sets the $var variable of in $object to 5.

Question still stands for ::

Thanks.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: What are the -> and :: operators?

Post by josh »

:: is static operator. -> isnt specific to variables. If your job is serious you should probably consider resigning now and save yourself the embarrassment, after you learn what you're doing there'll be plenty of opportunity for work. Not that you're not a very bright individual or anything but how would you feel if someone represented themselves as a car expert then you found out later they were asking their colleagues what the battery is for? You'd probably feel pretty scammed, wouldn't you?
terminator24h
Forum Newbie
Posts: 4
Joined: Mon Mar 02, 2009 11:43 pm

Re: What are the -> and :: operators?

Post by terminator24h »

Tremendously appreciated, thank you.

I take your advice to heart, but, with all due respect, I think you underestimate the extent to which knowledge of other programming languages can accelerate the learning curve. The way PHP deals with classes and objects is so similar to Java that I, as a somewhat-experienced Java programmer, can understand the code very easily once someone tells me what the weird operators here and there (like ::) do. It's not a heavy job by any standard -- upgrading a backend for a student-run summer storage company to accomodate another table in the database -- but it is serious (in that they will lose money if I don't do it).

Anyway, no flame intended.

Cheers :drunk:
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: What are the -> and :: operators?

Post by josh »

Good stuff, you got to realize how many people take on projects they can't handle and come on here asking for help, sorry to grill you!
Post Reply