17 replies [Last post]
Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 4 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2043
Points: 2268

I'm going to attempt to convert an old PHP script to ASP.NET just for kicks but I need to know some syntax. It's hard to search for operators because they are stripped out of google searches.

My first questions is what is the -> operator called and what does it do?

Tags:
Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 4 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2043
Points: 2268

Is $this a variable or the

Is $this a variable or the keyword "this"?

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 10 hours 10 min ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5342
Points: 2963

hi Verschwindende, This -> is

hi Verschwindende,
This -> is a pointer that points from an object to a property of the object.
Anything with $ in front of it is a variable. $this is a variable used within a class to reference the current object.

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 4 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2043
Points: 2268

Ah, thank you. It's like

Ah, thank you. Smile It's like the dot in object.property in any other language then, correct?

I dug out a book on PHP that I bought way back in 2003. OOP wasn't really mentioned other than a passing phrase about it may become more popular when PHP5 comes out.

Is there a way to search for punctuation and operators? Even the PHP site came up with nothing in their search box. For instance, just the other day, I couldn't remember what ?? was called (Null Coalescing Assignment Operator) and typing ?? into google gives you nothing.

I'm used to strongly typed languages. When I didn't see $this being defined I confused it with a keyword.

If I have something like this:

function SetMargins($left, $top, $right=null)
{
	//Set left, top and right margins
	$this->lMargin=$left;
	$this->tMargin=$top;
	if($right===null)
		$right=$left;
	$this->rMargin=$right;
}
I don't see a return in the function so what is the variable $this doing? Is the variable's scope contained in the function?

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 5 years 33 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

Did you come across

Did you come across http://php.net/manual/en/language.operators.php in your searching?

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 4 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2043
Points: 2268

Tyssen wrote:Did you come

Tyssen wrote:

Did you come across http://php.net/manual/en/language.operators.php in your searching?

Yes, but I didn't see -> defined. (edit - I see it now. Way down in the comments)

This is the library I'm going to attempt: http://fpdf.org/

I never could really get PHP. I may be in for a long hard ride.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 21 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Quote: It's like the dot in

Quote:

It's like the dot in object.property in any other language then

And enough with comments like that. Why choose a full stop when one can use something far cooler looking -> and two characters!

Quote:

I'm used to strongly typed languages

>) oh welcome to a whole world of pain.

The way I write it though would be referred to as 'strongly typed' Crazy

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 4 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2043
Points: 2268

Hugo wrote: ... And enough

Hugo wrote:

... And enough with comments like that. Why choose a full stop when one can use something far cooler looking -> and two characters!

HAHAA! Laughing out loud I knew I'd stir your pudding. Wink

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 4 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2043
Points: 2268

Backburner! Bah. PHP = feh!

Backburner! Bah. PHP = feh! Crazy

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 21 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

*Sigh* no perseverance. These

*Sigh* no perseverance. These youth of today; first sign of hard work and they give up Tongue PHP! how difficult can it be? ok don't answer that one Smile

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 4 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2043
Points: 2268

Best reply for calling me a

Best reply for calling me a youth! Laughing out loud

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 21 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

(No subject)

Laughing out loud

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 21 hours 12 min ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9759
Points: 3841

Objects and references

See Example #2 Some examples of the $this pseudo-variable.

Quote:

The pseudo-variable $this is available when a method is called from within an object context. $this is a reference to the calling object (usually the object to which the method belongs, but possibly another object, if the method is called statically from the context of a secondary object).

IOW, it's much like the javascript keyword, this.

See Example #1 References and Objects

Quote:

A PHP reference is an alias, which allows two different variables to write to the same value. As of PHP5, an object variable doesn't contain the object itself as value anymore. It only contains an object identifier which allows object accessors to find the actual object. When an object is sent by argument, returned or assigned to another variable, the different variables are not aliases: they hold a copy of the identifier, which points to the same object.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

rockersmith
rockersmith's picture
Offline
newbie
rockersmith
Last seen: 9 years 12 weeks ago
rockersmith
Timezone: GMT+5.5
Joined: 2011-03-09
Posts: 3
Points: 3

The information regarding the

The information regarding the php syntax that you have given above is very nice and also very beneficial for me as well as others who wants to know. I liked and very much impressed by this. I am very much thankful to you for giving me the exact information.

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 4 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2043
Points: 2268

^^^^ Fluff post.

^^^^
Fluff post.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 21 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

We're suffering a fluff

We're suffering a fluff attack - yikes to much fluff can't breath, suffocating. Where are those darn moderators when they're needed

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 21 hours 12 min ago
Dallas
Timezone: GMT-5
Joined: 2004-06-25
Posts: 9759
Points: 3841

Moderation in all things, and not too much of that either

Quote:

Where are those darn moderators when they're needed

Here I come to save the day.

Shall I remove the fluff posts, numbers 6, 7, 8, 9, 10, 11, 14, and 15? Posts 1 thru 5, and 12 are quite on topic. Number 13 is a quite brilliant comment by a sharp young mind who knows very well how to suck up to his betters.

Do all agree?

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 21 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Yeah go for it, remove all my

Yeah go for it, remove all my fluff posting Stare and there I was thinking what witty little posts I did make to cheer the forum along *sigh*

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me