FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » using same variable twice on same page
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Re: using same variable twice on same page [message #171376 is a reply to message #171340] Fri, 31 December 2010 01:59 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Peter H. Coffin wrote:
> On Thu, 30 Dec 2010 02:07:59 +0100, August Karlstrom wrote:
>> On 2010-12-29 11:42, Derek Turner wrote:
>>> On Tue, 28 Dec 2010 22:07:55 -0700, richard wrote:
>>>
>>>> <?php if ($year="1961")
>>>
>>> This simply sets $year to "1961" and will always return 'true'
>> ...which is more or less a flaw in the language design copied from C.
>
> ... and a correction of a flaw in any language design copied from
> Fortran. We can do this all day.
>
Oh yes. Fortran. I'd forgotten Fortran...those godawful number to string
printing statements..
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171377 is a reply to message #171344] Fri, 31 December 2010 02:07 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
August Karlstrom wrote:
> On 2010-12-30 05:47, Jerry Stuckle wrote:
>> On 12/29/2010 8:07 PM, August Karlstrom wrote:
>>> On 2010-12-29 11:42, Derek Turner wrote:
>>>> On Tue, 28 Dec 2010 22:07:55 -0700, richard wrote:
>>>>
>>>> > <?php if ($year="1961")
>>>>
>>>> This simply sets $year to "1961" and will always return 'true'
>>>
>>> ...which is more or less a flaw in the language design copied from C.
>>
>> Not at all. == is a completely different operator than =. Just like ++
>> is not the same as +.
>
> The equal sign `=' has been used in mathematics since medieval times to
> denote equality. To use `==' for equality and `=' for something else
> (assignment) is not sensible.
>
well in assembler its

MOV b,a
or
CMP a,b


And it used to be
LET a=b
and
if a=b

But the drive towards compactness on like editors meant that it got
turned into a=b;

You might argue endlessly about the need for two different operators and
whether 'a equals b' is more natural to regard as an assignment or a
comparison.

I argue that complex conditionals and assignments depending on them get
pretty screwed if you let the compiler decide what you really mean.

take

(a=b==c)

Its very clear which is an assignment and which is a comparison, though
the order or precedence is less so..

I don't know how you would write than in 'context dependent equals'
language, at all.


>
> /August
>
Re: using same variable twice on same page [message #171382 is a reply to message #171375] Fri, 31 December 2010 09:57 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <ifjdb0$r2s$2(at)news(dot)albasani(dot)net>,
The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:

> Tim Streater wrote:
>> In article <ifhj8t$1hd$2(at)news(dot)albasani(dot)net>,
>> The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:
>>
>>> August Karlstrom wrote:
>>>> On 2010-12-29 11:42, Derek Turner wrote:
>>>> > On Tue, 28 Dec 2010 22:07:55 -0700, richard wrote:
>>>> >
>>>> >> <?php if ($year="1961")
>>>> >
>>>> > This simply sets $year to "1961" and will always return 'true'
>>>> > ...which is more or less a flaw in the language design copied from C.
>>>
>>> Which is more or less a feature of clarity,....not a flaw.
>>>
>>> BASIC is the flawed language, allowing '=' to mean SET TO and EQUALS
>>> according to ambiguous context
>>>
>>> Sadly PHP copied BASICS lack of explicit typing as well.
>>
>> I don't want explicit typing. Let the language work for you.
>>
> I guess I am not lazy enough and prefer the language to do exactly what
> I tell it.

Well - there it is. So far it has :-)

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171383 is a reply to message #171377] Fri, 31 December 2010 10:14 Go to previous messageGo to next message
August Karlstrom is currently offline  August Karlstrom
Messages: 16
Registered: October 2010
Karma: 0
Junior Member
On 2010-12-31 03:07, The Natural Philosopher wrote:
[...]
> take
>
> (a=b==c)
>
> Its very clear which is an assignment and which is a comparison, though
> the order or precedence is less so..
>
> I don't know how you would write than in 'context dependent equals'
> language, at all.

I'm not advocating "context dependant equals"; I think that a different
symbol should be used for assignment, e.g. `:='.


/August

--
The competent programmer is fully aware of the limited size of his own
skull. He therefore approaches his task with full humility, and avoids
clever tricks like the plague. --Edsger Dijkstra
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171384 is a reply to message #171383] Fri, 31 December 2010 10:47 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
August Karlstrom wrote:
> On 2010-12-31 03:07, The Natural Philosopher wrote:
> [...]
>> take
>>
>> (a=b==c)
>>
>> Its very clear which is an assignment and which is a comparison, though
>> the order or precedence is less so..
>>
>> I don't know how you would write than in 'context dependent equals'
>> language, at all.
>
> I'm not advocating "context dependant equals"; I think that a different
> symbol should be used for assignment, e.g. `:='.
>
>

I thought a lot of things when I first tried to program a computer.

I probably thought a lot of things when as a 12 month old baby I tried
to learn English.


But I managed to struggle on with both, and I can now understand
important things like the difference between 'lose' and 'loser', and
'loose', and 'looser'. And '=' and '==' and '!='

Not to mention a number system mased on 10, a currency based on 240 and
a weights and measures system based on how many hoses' hooves you could
fry up for breakfast without being sick, or something equally arbitrary.

The important thing about standards and conventions is that they exist.

Less so what they are.



> /August
>
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171390 is a reply to message #171383] Fri, 31 December 2010 16:12 Go to previous messageGo to next message
Jim Higgins is currently offline  Jim Higgins
Messages: 20
Registered: November 2010
Karma: 0
Junior Member
On Fri, 31 Dec 2010 11:14:37 +0100, August Karlstrom
<fusionfile(at)gmail(dot)com> wrote:

> On 2010-12-31 03:07, The Natural Philosopher wrote:
> [...]
>> take
>>
>> (a=b==c)
>>
>> Its very clear which is an assignment and which is a comparison, though
>> the order or precedence is less so..
>>
>> I don't know how you would write than in 'context dependent equals'
>> language, at all.
>
> I'm not advocating "context dependant equals"; I think that a different
> symbol should be used for assignment, e.g. `:='.


You are welcome to think that, but you won't have much success
programming in PHP unless you use "=" for assignment.
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171391 is a reply to message #171390] Fri, 31 December 2010 16:33 Go to previous messageGo to next message
me is currently offline  me
Messages: 192
Registered: September 2010
Karma: 0
Senior Member
On 12/31/2010 11:12 AM, Jim Higgins wrote:
> On Fri, 31 Dec 2010 11:14:37 +0100, August Karlstrom
> <fusionfile(at)gmail(dot)com> wrote:
>
>> On 2010-12-31 03:07, The Natural Philosopher wrote:
>> [...]
>>> take
>>>
>>> (a=b==c)
>>>
>>> Its very clear which is an assignment and which is a comparison, though
>>> the order or precedence is less so..
>>>
>>> I don't know how you would write than in 'context dependent equals'
>>> language, at all.
>>
>> I'm not advocating "context dependant equals"; I think that a different
>> symbol should be used for assignment, e.g. `:='.
>
>
> You are welcome to think that, but you won't have much success
> programming in PHP unless you use "=" for assignment.
>


By analogy, write down the grade you are in ($grade=12). If you are in
12th grade (if $grade==12) then you may graduate at the end of the year
(all other things equal).

Bill B
Re: using same variable twice on same page [message #171461 is a reply to message #171191] Wed, 05 January 2011 01:00 Go to previous messageGo to next message
spambait is currently offline  spambait
Messages: 35
Registered: September 2010
Karma: 0
Member
In article <yzhlacpa809x(dot)dlg(at)evanplatt(dot)sux>, richard <member(at)newsguy(dot)com> wrote:
> Everything I have looked at so far talks of how to use one variable ONCE!
> Nothing I've seen even comes to close as to how to utilize the same
> variable in a different location on the same page.
>
> for instance:
> initial value of $year="1960"
> <div> <?php echo $year;?></div>
> <div> blah blah blah </div>
> <div> yada yada yada </div>
> Assume here we change $year to be "1961"

Mind showing us how you did that?

> <div> <?php if ($year="1961") echo $year; ?></div>
>
> From what I've tried, no change is made.

I'd imagine not.

> Even if I use a second instance of $_GET().
>
> What is the best way of doing what I want to happen?

Start by looking at the PHP manual to determine the correct operator to use
for making equality comparisons.
Re: using same variable twice on same page [message #171462 is a reply to message #171211] Wed, 05 January 2011 01:10 Go to previous messageGo to next message
spambait is currently offline  spambait
Messages: 35
Registered: September 2010
Karma: 0
Member
In article <javru7-7ht(dot)ln1(at)qqqqq(dot)xs4all(dot)nl>, Luuk <Luuk(at)invalid(dot)lan> wrote:
> On 29-12-10 15:15, Captain Paralytic wrote:
[...]
>>
>> Now either [Richard] has not had the intelligence to have searched for php
>> tutorials, or he has done them but has not had the intelligence to
>> understand anything he has done.
>
> Since when do you care about the intelligence of anyone else?
> He definitely wants to learn, otherwise he would not post a question here.

I don't agree that Richard wants to learn -- his posts don't indicate any
desire to increase his understanding, only a desire to be given the solution
to his immediate problem. Confucius supposedly said, "Give a man a fish, and
you feed him for a day. Teach him how to fish, and you feed him for a
lifetime." Richard wants only to be given fish, and actively resists being
guided to resources that will help him learn to fish.
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171621 is a reply to message #171353] Wed, 12 January 2011 15:50 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 12/30/2010 1:36 PM, Jim Higgins wrote:
> On Thu, 30 Dec 2010 15:35:10 +0100, August Karlstrom
> <fusionfile(at)gmail(dot)com> wrote:
>
>> On 2010-12-30 05:47, Jerry Stuckle wrote:
>>> On 12/29/2010 8:07 PM, August Karlstrom wrote:
>>>> On 2010-12-29 11:42, Derek Turner wrote:
>>>> > On Tue, 28 Dec 2010 22:07:55 -0700, richard wrote:
>>>> >
>>>> >> <?php if ($year="1961")
>>>> >
>>>> > This simply sets $year to "1961" and will always return 'true'
>>>>
>>>> ...which is more or less a flaw in the language design copied from C.
>>>
>>> Not at all. == is a completely different operator than =. Just like ++
>>> is not the same as +.
>>
>> The equal sign `=' has been used in mathematics since medieval times to
>> denote equality. To use `==' for equality and `=' for something else
>> (assignment) is not sensible.
>
>
> All fine and dandy if you're programming in BASIC, but when
> programming in PHP you'll either do it as PHP requires or you'll not
> get the result you expect. Sensible or not that's the way it is. Your
> choice.

Now hand him what "===" means :-)

I just stepped in from and haven't read the history of this thread.
However, just from this little bit I can see that he doesn't know
programming at all. I'll bet he even thinks that

$a = 11;

means that the variable $a is equal to 11 and that this is an equation.
(Hint August: It isn't an equation. It is an expression that you are
taking the value 11 and setting the value of 11 into to the memory
location denoted by the variable $a).

Programming != mathematics.

Anyway, perhaps August should pick up a book on C, C++, Java and see
what they use for tests of equality before he criticizes PHP.

--
Shelly
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171622 is a reply to message #171360] Wed, 12 January 2011 15:53 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 12/30/2010 2:45 PM, August Karlstrom wrote:
> On 2010-12-30 20:21, richard wrote:
>> On Thu, 30 Dec 2010 15:35:10 +0100, August Karlstrom wrote:
>>> The equal sign `=' has been used in mathematics since medieval times to
>>> denote equality. To use `==' for equality and `=' for something else
>>> (assignment) is not sensible.
>>
>> Not really. As in various programming languages dictate, usage and
>> display
>> can be quite different.
>>
>> In BASIC and simpler low level languages, we say<>, meaning "not equal"
>> while in the higher level languages we say, !=.
>
> The symbols `/=' and `#' are also used in some high-level languages. It
> is unfortunate that the not-equal-to sign is neither on a standard
> keyboard nor in the 7-bit ASCII table. As a general guideline, however,
> I don't think language designers should redefine the meaning of well
> known symbols from mathematics. Or why not let `+' be the
> increment-by-one operator and `++' denote addition? Why not? After all,
> as Jerry Stuckle mentioned, programming is not mathematics.
>
>
> /August
>

August, I am a very big fan of the New England Patriots football team.
The coach, Bill Belichik has a favorite expression -- "It is what it is".

IOW, live with it.

(This is a stupid thread).

--
Shelly
Re: using same variable twice on same page [message #171623 is a reply to message #171375] Wed, 12 January 2011 15:54 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 12/30/2010 8:57 PM, The Natural Philosopher wrote:
> Tim Streater wrote:
>> In article <ifhj8t$1hd$2(at)news(dot)albasani(dot)net>,
>> The Natural Philosopher <tnp(at)invalid(dot)invalid> wrote:
>>
>>> August Karlstrom wrote:
>>>> On 2010-12-29 11:42, Derek Turner wrote:
>>>> > On Tue, 28 Dec 2010 22:07:55 -0700, richard wrote:
>>>> >
>>>> >> <?php if ($year="1961")
>>>> >
>>>> > This simply sets $year to "1961" and will always return 'true'
>>>> > ...which is more or less a flaw in the language design copied
>>> from C.
>>>
>>> Which is more or less a feature of clarity,....not a flaw.
>>>
>>> BASIC is the flawed language, allowing '=' to mean SET TO and EQUALS
>>> according to ambiguous context
>>>
>>> Sadly PHP copied BASICS lack of explicit typing as well.
>>
>> I don't want explicit typing. Let the language work for you.
>>
> I guess I am not lazy enough and prefer the language to do exactly what
> I tell it.

I, too, would prefer strict typing as well. That would eliminate many
errors where you think you have numbers but really have strings.
However, on the whole, PHP is great.

--
Shelly
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171624 is a reply to message #171383] Wed, 12 January 2011 15:57 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 12/31/2010 5:14 AM, August Karlstrom wrote:
> On 2010-12-31 03:07, The Natural Philosopher wrote:
> [...]
>> take
>>
>> (a=b==c)
>>
>> Its very clear which is an assignment and which is a comparison, though
>> the order or precedence is less so..
>>
>> I don't know how you would write than in 'context dependent equals'
>> language, at all.
>
> I'm not advocating "context dependant equals"; I think that a different
> symbol should be used for assignment, e.g. `:='.
>
>
> /August
>

I can't recall. Which language does that?

--
Shelly
Re: OT: Assignment operator [message #171626 is a reply to message #171624] Wed, 12 January 2011 16:05 Go to previous messageGo to next message
Sherm Pendley is currently offline  Sherm Pendley
Messages: 33
Registered: September 2010
Karma: 0
Member
sheldonlg <sheldonlg(at)thevillages(dot)net> writes:

> On 12/31/2010 5:14 AM, August Karlstrom wrote:
>> On 2010-12-31 03:07, The Natural Philosopher wrote:
>> [...]
>>
>> I'm not advocating "context dependant equals"; I think that a different
>> symbol should be used for assignment, e.g. `:='.
>
> I can't recall. Which language does that?

Pascal, for one. I assume its descendants - Modula & Oberon - do so
as well.

sherm--

--
Sherm Pendley
<http://camelbones.sourceforge.net>
Cocoa Developer
Re: OT: Assignment operator [message #171627 is a reply to message #171626] Wed, 12 January 2011 18:43 Go to previous messageGo to next message
spambait is currently offline  spambait
Messages: 35
Registered: September 2010
Karma: 0
Member
In article <m2wrma6rbk(dot)fsf(at)sherm(dot)shermpendley(dot)com>, Sherm Pendley <sherm(dot)pendley(at)gmail(dot)com> wrote:
> sheldonlg <sheldonlg(at)thevillages(dot)net> writes:
>
>> On 12/31/2010 5:14 AM, August Karlstrom wrote:
>>> On 2010-12-31 03:07, The Natural Philosopher wrote:
>>> [...]
>>>
>>> I'm not advocating "context dependant equals"; I think that a different
>>> symbol should be used for assignment, e.g. `:='.
>>
>> I can't recall. Which language does that?
>
> Pascal, for one. I assume its descendants - Modula & Oberon - do so
> as well.

Likewise TAL and SPL.
Re: OT: Assignment operator [message #171628 is a reply to message #171627] Wed, 12 January 2011 18:47 Go to previous messageGo to next message
spambait is currently offline  spambait
Messages: 35
Registered: September 2010
Karma: 0
Member
In article <igkso5$i6r$1(at)news(dot)eternal-september(dot)org>, spambait(at)milmac(dot)com (Doug Miller) wrote:
> In article <m2wrma6rbk(dot)fsf(at)sherm(dot)shermpendley(dot)com>, Sherm Pendley
> <sherm(dot)pendley(at)gmail(dot)com> wrote:
>> sheldonlg <sheldonlg(at)thevillages(dot)net> writes:
>>
>>> On 12/31/2010 5:14 AM, August Karlstrom wrote:
>>>> On 2010-12-31 03:07, The Natural Philosopher wrote:
>>>> [...]
>>>>
>>>> I'm not advocating "context dependant equals"; I think that a different
>>>> symbol should be used for assignment, e.g. `:='.
>>>
>>> I can't recall. Which language does that?
>>
>> Pascal, for one. I assume its descendants - Modula & Oberon - do so
>> as well.
>
> Likewise TAL and SPL.

I should clarify: there are at least two different languages called SPL; I'm
referring to the HP 3000 series Systems Programming Language.
Re: OT: Assignment operator (Was: using same variable twice on same page) [message #171631 is a reply to message #171624] Wed, 12 January 2011 20:28 Go to previous messageGo to next message
Jim Higgins is currently offline  Jim Higgins
Messages: 20
Registered: November 2010
Karma: 0
Junior Member
On Wed, 12 Jan 2011 10:57:36 -0500, sheldonlg
<sheldonlg(at)thevillages(dot)net> wrote:

> On 12/31/2010 5:14 AM, wrote:
>>
>> I'm not advocating "context dependant equals"; I think that
>> a different symbol should be used for assignment, e.g. `:='.
>
> I can't recall. Which language does that?

Pascal
Re: OT: Assignment operator [message #171634 is a reply to message #171626] Wed, 12 January 2011 23:14 Go to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 1/12/2011 11:05 AM, Sherm Pendley wrote:
> sheldonlg<sheldonlg(at)thevillages(dot)net> writes:
>
>> On 12/31/2010 5:14 AM, August Karlstrom wrote:
>>> On 2010-12-31 03:07, The Natural Philosopher wrote:
>>> [...]
>>>
>>> I'm not advocating "context dependant equals"; I think that a different
>>> symbol should be used for assignment, e.g. `:='.
>>
>> I can't recall. Which language does that?
>
> Pascal, for one. I assume its descendants - Modula& Oberon - do so
> as well.
>
> sherm--
>
Thanks! I thought that was it, but it has been over twenty five years
since I touched Pascal (and even then it was very little), so I didn't
want to make a declarative statement only to have the response "No, it
isn't, you dummy" :-).

--
Shelly
Pages (2): [ «    1  2]  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: AND in the if statement
Next Topic: login script using file, not mysql
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 20:10:58 GMT 2024

Total time taken to generate the page: 0.02844 seconds