Jump to content

[SOLVED] This -> thingy


ngreenwood6

Recommended Posts

I am new to php and am trying to learn. I have the basics and can do some of the more complex stuff but the one thing that I do not get is the "->" What do you use that for? How do you use it and what does it mean when you use it? For example:

 

if(empty(username))
{
do this
}
else
{
do that
}

 

That means if the user didnt enter a username do this or if they did do that. Can someone explain to me how the "->" thing works in an example like above.

Link to comment
https://forums.phpfreaks.com/topic/124333-solved-this-gt-thingy/
Share on other sites

It's not that easy to give such a simple example. -> is used in object oriented code, to indicate properties and methods of  an object...

 

Let's take mysqli extension which is newer, better and in general 'improved' (hence mysqli) alternative to mysql.

 


$mysqli = new mysqli("localhost","user","password","database");

 

$mysqli is now an object of 'mysqli' class. This means it has all the methods (functions) and properties (variables) defined in mysqli class (you can look them up in manual of course).

 


if(! $mysqli->query("SELECT * FROM table")) echo $mysqli->error;

 

Now we're calling a query() method of $mysqli object (which acts just like mysql_query() ) and if it fails for some reason we echo 'error' variable of the same object (which gives the same information as mysql_query() in mysql extension).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.