Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #4148 > unrolled thread
| Started by | oldyork90 <oldyork90@yahoo.com> |
|---|---|
| First post | 2011-12-27 12:08 -0800 |
| Last post | 2012-01-09 14:49 +0000 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.php
scoping inside a block oldyork90 <oldyork90@yahoo.com> - 2011-12-27 12:08 -0800
Re: scoping inside a block The Natural Philosopher <tnp@invalid.invalid> - 2011-12-27 21:06 +0000
Re: scoping inside a block Gregor Kofler <usenet@gregorkofler.com> - 2012-01-09 14:31 +0100
Re: scoping inside a block The Natural Philosopher <tnp@invalid.invalid> - 2012-01-09 14:49 +0000
| From | oldyork90 <oldyork90@yahoo.com> |
|---|---|
| Date | 2011-12-27 12:08 -0800 |
| Subject | scoping inside a block |
| Message-ID | <428f81c5-8d7c-433d-aff2-86740e803459@q8g2000yqa.googlegroups.com> |
Is there a way to localize a var inside a block? Can I have this
behavior without calling a function?
$myA = 'A'
{
$myC = 'C';
$myA = 'B';
echo $myA . ' says B';
}
echo $myA . ' says A';
echo $myC .... does not exist
Thank you.
[toc] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2011-12-27 21:06 +0000 |
| Message-ID | <jddc1e$i8o$2@news.albasani.net> |
| In reply to | #4148 |
oldyork90 wrote:
> Is there a way to localize a var inside a block? Can I have this
> behavior without calling a function?
>
>
> $myA = 'A'
>
> {
> $myC = 'C';
> $myA = 'B';
> echo $myA . ' says B';
> }
>
> echo $myA . ' says A';
> echo $myC .... does not exist
>
>
> Thank you.
yeah,. Write the program in C :-)
[toc] | [prev] | [next] | [standalone]
| From | Gregor Kofler <usenet@gregorkofler.com> |
|---|---|
| Date | 2012-01-09 14:31 +0100 |
| Message-ID | <jeeq8d$90k$1@dont-email.me> |
| In reply to | #4148 |
Am 2011-12-27 21:08, schrieb oldyork90: > Is there a way to localize a var inside a block? No. Gregor
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2012-01-09 14:49 +0000 |
| Message-ID | <jeeuq5$1p8$1@news.albasani.net> |
| In reply to | #4352 |
Gregor Kofler wrote:
> Am 2011-12-27 21:08, schrieb oldyork90:
>> Is there a way to localize a var inside a block?
>
> No.
>
Strictly, no. In practice, make that block a function?
The overhead on a call return is not great.
Even if its only ever used once.
There is a lot to be said for making any long bit of code into a series
of calls to small functions to improve isolation, and separate
different logical flows.
So instead of if (this)
{
// Do pages of stuff...
}
eslsee {
// Do more pages of stuff
}
becomes if (this)
{
Do_pages_of_stuff($withThis, $andThis..);
}
else {
Do_more_pages_of_stuff($withThis, $andThis..);
}
etc etc.
I certainly find it helps me keep track of what the heck I am trying to
do a bit easier anyway.
The other way is of course massive documentation and commenting as we
used to do with Assembler, where the logical flow was completely
obscured by the actual language statements.
A block statement at the top explaining the flow, and comments
throughout like
;*********************
; In this section we compare gross profit with gross interest on loans
; Register A is the loan, B is the profit, in pence.
;*******************************************************
CMP A,B ; If the net cash flow is equal to the interest
JMPLT NO_PROFIT ; THEN prepare shareholder excuses
; ELSE etc ..
Which is megabytes of explanation for every few kilobytes of actual code..
The joy of discovering portable assembler AKA 'C' was...considerable.
Don't expect too much of your language: Just consider the alternatives....
> Gregor
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web