--- Marco Tabini <[EMAIL PROTECTED]> wrote:
> Well, you have to admit that the issue of variable scope is the first
> thing that hits someone who approaches PHP for the first time and
> comes from other backgrounds, like C or ASP!
> 
> Still, after one adapts to this apparent "weirdness" of scoping, it
> tends to grow on you. I find that no scope inheritance gives me one
> less thing to worry about when writing code...

While some of the scoping tricks proposed seem like potential overkill,
I've yearned for a way to explicitly declare a variable a
"super-global".  Sure, I can stick it in one of the predefined
super-globals, but that just seems wrong.

Something like: 

super $avar;

would be very useful for large projects and wouldn't cause a lot of
harm otherwise.

Hans


> 
> 
> Marco
> 
> On Sun, 2002-10-20 at 22:41, Rasmus Lerdorf wrote:
> > How in the world do you know that "code will run faster" ?
> > 
> > Implementing your suggestion would take quite a lot of changes to
> the
> > internals of PHP.  Instead of just a global and a current symbol
> table, we
> > would now need basically an unlimited number of symbol tables and
> every
> > variable lookup would become more complex.  Ergo it would slow
> things
> > down.
> > 
> > -Rasmus
> > 
> > On Mon, 21 Oct 2002, NTPT wrote:
> > 
> > > Hi.
> > > I have some idea and suggestion  how to extend PHP language a bit
> in some
> > > way. That may probably lead to increasing of php flexibility,
> allow more
> > > modular coding to be done etc....
> > >
> > >
> > > My sugestion is simple:
> > > Allow  PHP programmer to explicitelly  told , WHAT variable scope
> will be
> > > used  inside user defined  functions.
> > >
> > > In the traditional approach (afaik , i use php 4.2.2 ), as is
> described in
> > > the manual of php there a diferent varable scopes for each
> functions , only
> > > syntax " global $valuename" ; can lead to use variables global.
> This aproach
> > > is traditional and well known and is sufficient for most tasks.(I
> say
> > > sufficient, not effective...). My idea is going a bit behind it.
> > >
> > > I suggest  to introduce new keyword(s) or function(s)  into the
> PHP language
> > > definiton
> > > (i suggest syntax like  "var_scope scope" or  var_scope("scope")
> )
> > >
> > > That keywords SHOULD be used in user defined  functions to 
> EXPLICITLY
> > > define, WHAT kind of variable scope will be used inside this
> function.
> > >
> > > scope can be either
> > >
> > > 'local' = it means, that all variables used in this function 
> have a local
> > > scope only.(it means like traditional behavior of php and its
> variable
> > > scopes until now )
> > >
> > > 'global' = each variable used in the function  is from global
> scope. Similar
> > > to "global $variable_1,$variable_2........... $each variable used
> in the
> > > main execution line of the script"
> > >
> > > 'caller' or 'inherit' This is MOST USEFUL part of the idea .
> Function
> > > variable scope is the SAME as from where the function was called.
> (if
> > > functino bar(),with have var_scope set to 'caller', is called
> from function
> > > foo() it have the same variable scope as function foo(), almost
> like the
> > > code of function bar() was included (by include "something" )
> somewhere
> > > inside foo() )
> > >
> > >
> > > A little example code for demonstrating idea of the syntax and
> how it should
> > > work:
> > > */
> > > <?
> > >
> > > $a=10;
> > >
> > > echo "Varaible $a".$a;
> > > .
> > > $foo_output =foo();
> > > echo "<br>value returnded by foo() ".$foooutput;
> > > echo "<br>value $a after  calling  foo() but before calling bar()
> ".$a;
> > >
> > > $bar_output=bar();
> > > echo "<br>value returnded by bar() ".$bar_output;
> > > .
> > > .
> > > echo "<br>value $a after  calling  bar() ".$a;
> > >
> > > function foo()
> > >  {
> > >  $a=20;
> > >  echo "$a inside function foo() = ".$a
> > >  /* $bar_inside foo = bar();
> > >  echo "Variable $a inside function foo() after calling bar()".$a;
> > >
> > >  */
> > >  .
> > >  .
> > >
> > >  return $a;
> > >
> > >  }
> > >
> > >
> > > function bar()
> > >  {
> > >  var_scope caller // we have the SAME variable scope  as from
> where we are
> > > called
> > >  $a=100;
> > >  .
> > >  .
> > >  .
> > >  return $a;
> > >  }
> > > ?>
> > > this should return :  (with comments behind // )
> > >
> > > Varaible $a" 10
> > > $a inside function foo() = 20
> > > value returnded by foo() 20
> > > value $a after  calling  foo() but before calling bar() 10
> > > value returnded by bar() 100
> > > value $a after  calling  bar() 100  //  var_scope is set to
> 'caller', so $a
> > > in global scope is modified inside bar() the some way, as if
> global $a was
> > > used )
> > >
> > > if you uncomment lines in  bar()....
> > >
> > > Varaible $a" 10
> > > $a inside function foo() = 20
> > > Variable $a inside function foo() after calling bar() 100  //
> var_scope in
> > > function bar() is set to caller, so $a IN SCOPE of foo() ONLY  is
> modified
> > > inside bar().
> > >
> > > value returnded by foo() 100
> > > value $a after  calling  foo() but before calling bar() 10 //
> var_scope in
> > > function bar() is set to caller, so $a IN GLOBAL SCOPE is NOT
> modified
> > > inside bar().
> > > value returnded by bar() 100
> > > value $a after  calling  bar() 100  // var_scope is set to
> caller, so $a in
> > > global scope is modified inside bar() the some waz, as if global
> $a was used
> > >
> > >
> > > For WHAT it could be useful ??
> > >
> > >
> > > for example for writing a  databaze extraction layer of any
> aplication.
> > > common  real life situations are similar like in this  example
> code
> > > (simplified  and abstracted from real life code of PHP
> application I
> > > currently write  )....
> > >
> > > <?
> > > .
> > > .
> > > .
> > > .
> > > do something
> > > .
> > > .
> > > .
> > > // now you need a call subroutine
> > >
> > > $something=foo('cats','dogs','horses');
> > > .
> > > $different=bar('mices','meat','gras');
> 
=== message truncated ===


=====
Hans Zaunere
New York PHP
http://nyphp.org
[EMAIL PROTECTED]

__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to