For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > December 2004 > php4 (variable scope)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author php4 (variable scope)
Keith R

2004-12-23, 3:58 pm

Seasons greetings NG,

I have a php4/mysql4/iis6 setup.

I have several applications running on the above platform.. We selected the
platform for a number of reasons one of which was the availability of the C
(98?) language. .We have come across an issue I cannot explain, I wonder if
anyone has any insights? To cut to the chase when we query the database &
return more than 9000 rows we cannot get scripts to execute & behave as we
expect. Regardless of the number of rows returned execution only occurs
for one iteration if the number of rows returned is greater the 9000. After
some investigation we found that it was an issue with variable scope. A
truncated example follows:

//query database, get the data etc
//...script is executing
//someValue is greater than 9000

for$i=0;$i<someValue;++$i{
//do something
}

//redeclare $i, IMO first $i should be out of scope
for$i=0;$i<someValue;++$i{
//do something
}

....rest of execution

renaming $i in the 2nd scope to any other name not in the script so that
each control variable has a unique name appears to solve the problem.
However I was under the impression that my redeclaration of $i in my second
scope was legal. Assuming I am incorrect & it is illegal; the 9000 rows
value I assume is simply UB?

TIA
Keith


Keith R

2004-12-23, 3:58 pm


..
> However I was under the impression that my redeclaration of $i in my
> second scope was legal.


I am now aware that my declaration(s) of $i for the C90 standard neither
declaration is legal. For C99, both are. This leads me to ask which C
standard is php4 based upon?

Regards,
Keith



Colin McKinnon

2004-12-23, 8:56 pm

Keith R spilled the following:

>
> .
>
> I am now aware that my declaration(s) of $i for the C90 standard
> neither
> declaration is legal. For C99, both are. This leads me to ask which C
> standard is php4 based upon?
>
> Regards,
> Keith


PHP is not C, never has been, never will.

The code you published will not run in PHP

The code you will not compile with C

(both languages require the 'for' construct's parameters to be enclosed in
brackets:
for ($i=1; $i<$some_value;$i++) { // for PHP
for (i=1; i<some_value; i++) { // for C
)

....and C90 is a standard for audio cassettes, not programming languages.
Although C90 has been used as nickname for ISO/IEC 9989:1990 it's unlikely
that most people reading this newsgroup would be aware of that.

....oh and even if the code did behave as you say it does - that's not a
scope issue.

Want to try again?

C.

Oli Filth

2004-12-23, 8:56 pm

In PHP, one does not declare variables, it is perfectly acceptable to
use $i as you are doing; the PHP interpreter deals with it all.

PHP isn't based on any C standard, it just has some syntax in common,
but then so does Java, JavaScript, etc...

Can you post a more in-depth code sample, to show us what you're
actually doing with the MySQL results, etc.?

Oli

Keith R wrote:
> .
>
>
>
> I am now aware that my declaration(s) of $i for the C90 standard neither
> declaration is legal. For C99, both are. This leads me to ask which C
> standard is php4 based upon?
>
> Regards,
> Keith
>
>
>

Colin McKinnon

2004-12-28, 8:59 am

Keith R spilled the following:

>
> .
>
> I am now aware that my declaration(s) of $i for the C90 standard
> neither
> declaration is legal. For C99, both are. This leads me to ask which C
> standard is php4 based upon?
>
> Regards,
> Keith


PHP is not C, never has been, never will.

The code you published will not run in PHP

The code you will not compile with C

(both languages require the 'for' construct's parameters to be enclosed in
brackets:
for ($i=1; $i<$some_value;$i++) { // for PHP
for (i=1; i<some_value; i++) { // for C
)

....and C90 is a standard for audio cassettes, not programming languages.
Although C90 has been used as nickname for ISO/IEC 9989:1990 it's unlikely
that most people reading this newsgroup would be aware of that.

....oh and even if the code did behave as you say it does - that's not a
scope issue.

Want to try again?

C.

Oli Filth

2004-12-28, 8:59 am

In PHP, one does not declare variables, it is perfectly acceptable to
use $i as you are doing; the PHP interpreter deals with it all.

PHP isn't based on any C standard, it just has some syntax in common,
but then so does Java, JavaScript, etc...

Can you post a more in-depth code sample, to show us what you're
actually doing with the MySQL results, etc.?

Oli

Keith R wrote:
> .
>
>
>
> I am now aware that my declaration(s) of $i for the C90 standard neither
> declaration is legal. For C99, both are. This leads me to ask which C
> standard is php4 based upon?
>
> Regards,
> Keith
>
>
>

Keith R

2004-12-28, 3:56 pm


..
> However I was under the impression that my redeclaration of $i in my
> second scope was legal.


I am now aware that my declaration(s) of $i for the C90 standard neither
declaration is legal. For C99, both are. This leads me to ask which C
standard is php4 based upon?

Regards,
Keith



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com