Some basic question about PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paleredstream
Forum Newbie
Posts: 1
Joined: Mon Jan 17, 2011 6:08 pm

Some basic question about PHP

Post by paleredstream »

Hello
I've just started to learn PHP and had somewhat too basic question about language
I'll show code first

Code: Select all

#Code start
$First = "name1";

$$First = "IVR Test";
printf("%s\n", $name1);

$First = "name2";		
#unset($First)		<- problem code
#printf("%s\n", $name2); <- problem code
			
printf("%s\n", $name1);
# code ends



I'm testing indirect referencing, and when I uncomment "unset($First)", then interpreter gives error about
last printf($name1)
I'm curious
1. If indirect referencing(IR from here...) work by string "value",
(I have to guess like this because of printf($name1), where "name1" was the string value of $First)

then why unsetting $first affects last printf?
because I guess string value(not variable itself) is already used as name, and now $$First is nothing to do with $First

2. If IR work by referencing $First variable itself(somewhat like a pointer, or "real reference"), then why string value is necessary?
why just not print($$First)?

3. I changed value of %First to "name2" AFTER I assign IR,
but i can't access to $$First with printf("%s\n", $name2);
I can't understand this with either 1 or 2

Excuse my poor English, thank in advance
Last edited by Benjamin on Mon Jan 17, 2011 7:28 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: Some basic question about PHP

Post by Peter Kelly »

I've never used printf before I don't think but I would also like to know, as I'm not sure why you have done the $$First.
Post Reply