ngreenwood6 Posted September 15, 2008 Share Posted September 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/124333-solved-this-gt-thingy/ Share on other sites More sharing options...
wildteen88 Posted September 15, 2008 Share Posted September 15, 2008 This is explained in the FAQ/Code Snippet Repository Quote Link to comment https://forums.phpfreaks.com/topic/124333-solved-this-gt-thingy/#findComment-642069 Share on other sites More sharing options...
Mchl Posted September 15, 2008 Share Posted September 15, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/124333-solved-this-gt-thingy/#findComment-642074 Share on other sites More sharing options...
ngreenwood6 Posted September 15, 2008 Author Share Posted September 15, 2008 Thanks for the responses guys. That cleared it up for me. Quote Link to comment https://forums.phpfreaks.com/topic/124333-solved-this-gt-thingy/#findComment-642077 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.