?
Solved

Php ->

Posted on 2012-09-04
3
Medium Priority
?
373 Views
Last Modified: 2012-09-04
I'm trying to learn some basics of php, but still do understand when using the (->), like example (is to call a method inside a class?):

$myrows = $wpdb->get_results( "SELECT id, name FROM mytable" );
0
Comment
Question by:rflorencio
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Slimshaneey earned 1200 total points
ID: 38362680
-> is for an object instantiated, :: for static methods.

You should take ten minutes to read through this:
http://php.net/manual/en/language.oop5.php

It will give you the basics of OO programming with PHP. In particular, look at Instantiation (Creating objects), Class resolution and scope. It should hopefully get your basic knowledge more complete!
0
 
LVL 11

Assisted Solution

by:Slimshaneey
Slimshaneey earned 1200 total points
ID: 38362686
An example of the difference between an instantiated operator and static is like this:

class nonStatic {
public function hello(){
 return "Hello!"
}
}

class staticclass {
public static function hello(){
return "Hello!"
}
}

To call either of these:
$obj = new nonStatic;

$output = $obj->hello();
echo $output;

$outputStatic = staticclass::hello();
echo $output;

Open in new window

The main difference between calling static and non-static methods is the non-static has functions like __construct that run when the object is first created and can setup variables for use throught the life of that object. Statics dont have that but are quicker to run generally.
0
 
LVL 61

Assisted Solution

by:Julian Hansen
Julian Hansen earned 800 total points
ID: 38362687
The -> denotes a member of an object

So if you have
class MyClass
{
    // This is a variable local to the class. Each object of type MyClass will have
    // its own version of this variable - called an attribute
    // Here it is public which means it can be accessed outside of the class

    public $name = '';

    // This is a member  function in the class
    function set_name($newname)
    {
        // Here we are using $this which an object uses to refer to itself, to set
        // the member variable name to the newname 
        $this->name = $newname
    }
}

Open in new window

We can now create a new object of type myClass like this
// Create the class
$me = new MyClass();

// Call the function set_name the -> means member of
$me->set_name('Bob');

// Display the value of this object's internal name variable
echo $me->name;

Open in new window


Your post is basically showing a line that says

Object: $wpdb is calling an internal function called get_results.

So in answer to your question - yes it is to call a method in a class or to refer to a member variable (attribute)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question