Jump to content

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.