Re: [PHP] put code into a function then the code dead,very strange.

2011-08-02 Thread Sharl.Jimh.Tsin
BTW,why my previous post was rejected by the mail server as spam?


Re: [PHP] put code into a function then the code dead,very strange.

2011-08-02 Thread Sharl.Jimh.Tsin
all right,Richard.i pretty agree with you and always think that NOT 'many'
but ALL languages should have Variety Scope.

And i do not want access the ALL variety in any function/page,as you said,
that's poor design.

I just feel a bit surprise that the function can not access the variety
which located and defined in the same/current page except the GLOBAL
modifier.(although the thinking  is wrong in fact later)

That's all.


Re: [PHP] put code into a function then the code dead,very strange.

2011-08-02 Thread Daniel Brown
On Tue, Aug 2, 2011 at 10:24, Richard Quadling  wrote:
>
> For many many languages, scope is essential. PHP has had scope since
> day 1 (OK, I'm pretty sure PHP has had scope since day 1).

Depending on which generation/incarnation of PHP you mean, you're
correct.  Forms Interpreter (PHP/FI and PHP/FI 2.0) had variable
scope, but the original - the very Granddaddy, Personal HomePage Tools
- did not, if memory serves.  That initial implementation was actually
nothing more than a small series of Perl scripts.  When Rasmus rewrote
everything in C, that's when variable scoping was introduced (again,
fairly certain).

-- 

Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] put code into a function then the code dead,very strange.

2011-08-02 Thread Richard Quadling
On 2 August 2011 13:45, Sharl.Jimh.Tsin  wrote:
> 在 2011-08-02二的 13:33 +0100,Richard Quadling写道:
>
>> It is to do with variable scope.
>>
>> http://uk.php.net/manual/en/language.variables.scope.php /
>> http://uk.php.net/manual/zh/language.variables.scope.php
>>
>
> Thanks for your useful URL.According to the doc,i must make the var
> global by using "$GLOBALS" so that access it in the same page/context.
>
> just a bit unbelievable...HAHA.


For many many languages, scope is essential. PHP has had scope since
day 1 (OK, I'm pretty sure PHP has had scope since day 1).

It is also considered poor design to have all your variables in the
global scope.

It means that you have to remember every single variable name you've
ever used in every include file so that you don't conflict with one if
it is currently in use.

It also means that all data is always available all the time.

For many developers, this would be a serious issue.

If you are happy to live with these constraints, then you are
certainly able to put all your variables in the global scope and PHP
will quite happily help you by the use of $GLOBALS and global.

But you will find yourself doing a LOT of additional work as you will
have to type $GLOBAL['var'] for every single variable outside of a
function or method, or you will have to declare the variables as
global inside every function and method or you will have to pass the
variables to the function or method as a parameter.



-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] put code into a function then the code dead,very strange.

2011-08-02 Thread Sharl.Jimh.Tsin
在 2011-08-02二的 13:33 +0100,Richard Quadling写道:

> It is to do with variable scope.
> 
> http://uk.php.net/manual/en/language.variables.scope.php /
> http://uk.php.net/manual/zh/language.variables.scope.php
> 

Thanks for your useful URL.According to the doc,i must make the var
global by using "$GLOBALS" so that access it in the same page/context.

just a bit unbelievable...HAHA.

-- 
Best regards,
Sharl.Jimh.Tsin (From China **Obviously Taiwan INCLUDED**)

Using Gmail? Please read this important notice:
http://www.fsf.org/campaigns/jstrap/gmail?10073.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] put code into a function then the code dead,very strange.

2011-08-02 Thread Richard Quadling
On 2 August 2011 13:24, Sharl.Jimh.Tsin  wrote:
> 在 2011-08-02二的 22:29 +1200,Simon J Welsh写道:
>
>> You're using $motoCols in your function, but have not defined it or passed 
>> it as an argument.
>> ---
>> Simon Welsh
>> Admin of http://simon.geek.nz/
>>
>
> YES,thanks for taking me out.and i just have a question that the variety
> $motoCols has been defined with the function "processJSONtoSQL" together
> in the common.php which is imported into the main page at head.
>
> so WHY $motoCols can not be reachable by the function in one page?

It is to do with variable scope.

http://uk.php.net/manual/en/language.variables.scope.php /
http://uk.php.net/manual/zh/language.variables.scope.php

-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] put code into a function then the code dead,very strange.

2011-08-02 Thread Sharl.Jimh.Tsin
在 2011-08-02二的 22:29 +1200,Simon J Welsh写道:

> You're using $motoCols in your function, but have not defined it or passed it 
> as an argument.
> ---
> Simon Welsh
> Admin of http://simon.geek.nz/
> 

YES,thanks for taking me out.and i just have a question that the variety
$motoCols has been defined with the function "processJSONtoSQL" together
in the common.php which is imported into the main page at head.

so WHY $motoCols can not be reachable by the function in one page?


-- 
Best regards,
Sharl.Jimh.Tsin (From China **Obviously Taiwan INCLUDED**)

Using Gmail? Please read this important notice:
http://www.fsf.org/campaigns/jstrap/gmail?10073.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] put code into a function then the code dead,very strange.

2011-08-02 Thread Simon J Welsh
On 2/08/2011, at 10:24 PM, Sharl.Jimh.Tsin wrote:

> hi,everyone
>   it is a very strange problem,At first,i put my code into the method
> inner,it works.see below:
> 
> [snip]
> 
> As you can see,it seems to be impossible.Can someone tell me WHY?
> 
> -- 
> Best regards,
> Sharl.Jimh.Tsin (From China **Obviously Taiwan INCLUDED**)

You're using $motoCols in your function, but have not defined it or passed it 
as an argument.
---
Simon Welsh
Admin of http://simon.geek.nz/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php