php-general Digest 2 Aug 2011 21:18:47 -0000 Issue 7425
Topics (messages 314268 through 314287):
New version : EasyPHP 5.3.7 RC4 with PHP 5.3.7 RC4
314268 by: EasyPHP
put code into a function then the code dead,very strange.
314269 by: Sharl.Jimh.Tsin
314270 by: Simon J Welsh
314271 by: Sharl.Jimh.Tsin
314273 by: Richard Quadling
314274 by: Sharl.Jimh.Tsin
314275 by: Richard Quadling
314277 by: Daniel Brown
314285 by: Sharl.Jimh.Tsin
314286 by: Sharl.Jimh.Tsin
Re: Keyword Constructor
314272 by: Richard Quadling
$_POST value disappearing?
314276 by: Donovan Brooke
314278 by: Jônatas Zechim
314279 by: Florian Lemaitre
314280 by: Shawn McKenzie
314281 by: Richard Quadling
314282 by: Richard Quadling
314283 by: Steve Staples
314284 by: Donovan Brooke
testing
314287 by: Jim Giner
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
Hi
PHP 5.3.7 RC4 is now included in a the Wamp package EasyPHP 5.3.7 RC4.
Enjoy!
Website : www.easyphp.org
Screenshots : www.easyphp.org/screenshots.php
Facebook page : www.facebook.com/easywamp
Twitter : www.twitter.com/easyphp
--- End Message ---
--- Begin Message ---
hi,everyone
it is a very strange problem,At first,i put my code into the method
inner,it works.see below:
******************* start
$str = "SQL HERE";
if (1 == 1) {
$array = preg_split("~[^\"],~", $body);
for ($index1 = 0; $index1 < count($motoCols); $index1++) {
$tmp = "";
for ($index = 0; $index < count($array); $index++) {
//取出每个JSON块
if ($index == count($array) - 1) {
$tempStr = $array[$index];
} else {
$tempStr = $array[$index] . "}";
}
//转换成JSON 对象
$json = json_decode($tempStr);
//过滤掉数据库中的非法字段
if (!in_array($json->key, $motoCols)) {
continue;
}
if ($json->key == $motoCols[$index1]) {
$tmp = $json->val;
if ($index == 10 || $index == 12 || $json->key ==
"DeviceRepairCount") {
$tmp .= ",";
} else {
$tmp = "'" . $tmp . "',";
}
break;
} else {
if ($json->key == "DeviceRepairCount") {
$tmp = "0,";
} else {
$tmp = "'0',";
}
}
}
$str .= $tmp;
}
$str = substr($str, 0, -1) . ",LAST_INSERT_ID())";
}
$mysqli->query($str);
************************** end
and,when i move this process-code into a separate function,and invoke
it.it failed.see below:
********************** start
function processJSONtoSQL($s,$b) {
$array = preg_split("~[^\"],~", $b);
for ($index1 = 0; $index1 < count($motoCols); $index1++) {
$tmp = "";
for ($index = 0; $index < count($array); $index++) {
//取出每个JSON块
if ($index == count($array) - 1) {
$tempStr = $array[$index];
} else {
$tempStr = $array[$index] . "}";
}
//转换成JSON 对象
$json = json_decode($tempStr);
//过滤掉数据库中的非法字段
if (!in_array($json->key, $motoCols)) {
continue;
}
if ($json->key == $motoCols[$index1]) {
$tmp = $json->val;
if ($index == 10 || $index == 12 || $json->key ==
"DeviceRepairCount") {
$tmp .= ",";
} else {
$tmp = "'" . $tmp . "',";
}
break;
} else {
if ($json->key == "DeviceRepairCount") {
$tmp = "0,";
} else {
$tmp = "'0',";
}
}
}
$s .= $tmp;
}
return substr($s, 0, -1);
}
invoke part:
$str = "SQL HERE";
$str = processJSONtoSQL($str, $body) . ",LAST_INSERT_ID())";
$mysqli->query($str);
*************************** end
As you can see,it seems to be impossible.Can someone tell me WHY?
--
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.
--- End Message ---
--- Begin Message ---
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/
--- End Message ---
--- Begin Message ---
在 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.
--- End Message ---
--- Begin Message ---
On 2 August 2011 13:24, Sharl.Jimh.Tsin <amoiz.sh...@gmail.com> 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
--- End Message ---
--- Begin Message ---
在 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.
--- End Message ---
--- Begin Message ---
On 2 August 2011 13:45, Sharl.Jimh.Tsin <amoiz.sh...@gmail.com> 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
--- End Message ---
--- Begin Message ---
On Tue, Aug 2, 2011 at 10:24, Richard Quadling <rquadl...@gmail.com> 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).
--
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/
--- End Message ---
--- Begin Message ---
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.
--- End Message ---
--- Begin Message ---
BTW,why my previous post was rejected by the mail server as spam?
--- End Message ---
--- Begin Message ---
On 2 August 2011 06:28, Ren <lobbyjo...@gmail.com> wrote:
> For a long time I wanted keyword parameters in PHP. But thanks to
> newer features like traits and reflection classes I have come up with
> something that looks pretty close.
>
> trait KeywordConstructor {
> public function __construct($members) {
> $class = new ReflectionClass($this);
> $properties = $class->getProperties();
>
> foreach ($properties as $p) {
> $name = $p->getName();
>
> if (isset($members[$name])) {
> $this->$name = $members[$name];
> }
> }
> }
> }
>
> class User {
> use KeywordConstructor;
> private $name;
> private $age;
> }
>
> $lobby = new User(['name' => 'Lobby', 'age' => 36]);
>
> Right now this requires the trunk version of PHP to work. I just
> wanted to share this in case anyone finds it interesting and/or
> useful.
I use a similar technique when I need to populate a SOAP class on the
server to coerce data from the DB into the appropriate type as defined
in the docblock of the class.
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
--- End Message ---
--- Begin Message ---
Hello!,
I must not be understanding something as I would expect 'f_file'
to show up in the print_r below.:
---form--
<form action="index.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="f_ap" value="upload" />
<input type="hidden" name="f_action" value="doit" />
<input type="file" name="f_file" />
<input type="submit" value="Upload" />
</form>
---endform--
--index.php--
<?php print_r($_POST); ?>
--/index.php--
The result I get is:
------------
Array
(
[f_ap] => upload
[f_action] => doit
)
-----------
Can someone enlighten me?
Thanks,
Donovan
--
D Brooke
--- End Message ---
--- Begin Message ---
Hi..
You need to use $_FILES (
http://php.net/manual/pt_BR/reserved.variables.files.php)
Regards,
Jônatas Zechim
PHP & jQuery specialist
http://zechim.com
mob +55 11 7053 2239
skype ID zechim
On 2 August 2011 12:04, Donovan Brooke <li...@euca.us> wrote:
> Hello!,
>
> I must not be understanding something as I would expect 'f_file'
> to show up in the print_r below.:
>
> ---form--
> <form action="index.php" method="post" enctype="multipart/form-data">
> <input type="hidden" name="f_ap" value="upload" />
> <input type="hidden" name="f_action" value="doit" />
> <input type="file" name="f_file" />
> <input type="submit" value="Upload" />
> </form>
> ---endform--
>
> --index.php--
> <?php print_r($_POST); ?>
> --/index.php--
>
>
>
>
> The result I get is:
> ------------
> Array
> (
> [f_ap] => upload
> [f_action] => doit
> )
> -----------
>
> Can someone enlighten me?
>
> Thanks,
> Donovan
>
>
> --
> D Brooke
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Le 02/08/2011 17:04, Donovan Brooke a écrit :
Hello!,
I must not be understanding something as I would expect 'f_file'
to show up in the print_r below.:
--index.php--
<?php print_r($_POST); ?>
--/index.php--
try *:
*<?php print_r($_FILES); ?>
;)
--- End Message ---
--- Begin Message ---
On 08/02/2011 10:04 AM, Donovan Brooke wrote:
> Hello!,
>
> I must not be understanding something as I would expect 'f_file'
> to show up in the print_r below.:
>
> ---form--
> <form action="index.php" method="post" enctype="multipart/form-data">
> <input type="hidden" name="f_ap" value="upload" />
> <input type="hidden" name="f_action" value="doit" />
> <input type="file" name="f_file" />
> <input type="submit" value="Upload" />
> </form>
> ---endform--
>
> --index.php--
> <?php print_r($_POST); ?>
> --/index.php--
>
>
>
>
> The result I get is:
> ------------
> Array
> (
> [f_ap] => upload
> [f_action] => doit
> )
> -----------
>
> Can someone enlighten me?
>
> Thanks,
> Donovan
>
>
The manual is great! $_FILES
http://www.php.net/manual/en/features.file-upload.post-method.php
--
Thanks!
-Shawn
http://www.spidean.com
--- End Message ---
--- Begin Message ---
On 2 August 2011 16:04, Donovan Brooke <li...@euca.us> wrote:
> Hello!,
>
> I must not be understanding something as I would expect 'f_file'
> to show up in the print_r below.:
>
> ---form--
> <form action="index.php" method="post" enctype="multipart/form-data">
> <input type="hidden" name="f_ap" value="upload" />
> <input type="hidden" name="f_action" value="doit" />
> <input type="file" name="f_file" />
> <input type="submit" value="Upload" />
> </form>
> ---endform--
>
> --index.php--
> <?php print_r($_POST); ?>
> --/index.php--
>
>
>
>
> The result I get is:
> ------------
> Array
> (
> [f_ap] => upload
> [f_action] => doit
> )
> -----------
>
> Can someone enlighten me?
Check out $_FILES for the file upload information.
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
--- End Message ---
--- Begin Message ---
On 2 August 2011 16:11, Richard Quadling <rquadl...@gmail.com> wrote:
> On 2 August 2011 16:04, Donovan Brooke <li...@euca.us> wrote:
>> Hello!,
>>
>> I must not be understanding something as I would expect 'f_file'
>> to show up in the print_r below.:
>>
>> ---form--
>> <form action="index.php" method="post" enctype="multipart/form-data">
>> <input type="hidden" name="f_ap" value="upload" />
>> <input type="hidden" name="f_action" value="doit" />
>> <input type="file" name="f_file" />
>> <input type="submit" value="Upload" />
>> </form>
>> ---endform--
>>
>> --index.php--
>> <?php print_r($_POST); ?>
>> --/index.php--
>>
>>
>>
>>
>> The result I get is:
>> ------------
>> Array
>> (
>> [f_ap] => upload
>> [f_action] => doit
>> )
>> -----------
>>
>> Can someone enlighten me?
>
> Check out $_FILES for the file upload information.
http://php.net/manual/en/features.file-upload.php
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
--- End Message ---
--- Begin Message ---
On Tue, 2011-08-02 at 10:04 -0500, Donovan Brooke wrote:
> Hello!,
>
> I must not be understanding something as I would expect 'f_file'
> to show up in the print_r below.:
>
> ---form--
> <form action="index.php" method="post" enctype="multipart/form-data">
> <input type="hidden" name="f_ap" value="upload" />
> <input type="hidden" name="f_action" value="doit" />
> <input type="file" name="f_file" />
> <input type="submit" value="Upload" />
> </form>
> ---endform--
>
> --index.php--
> <?php print_r($_POST); ?>
> --/index.php--
>
>
>
>
> The result I get is:
> ------------
> Array
> (
> [f_ap] => upload
> [f_action] => doit
> )
> -----------
>
> Can someone enlighten me?
>
> Thanks,
> Donovan
try print_r($_FILE) (i think, it's either FILE or FILES)
Steve.
--- End Message ---
--- Begin Message ---
Jônatas Zechim wrote:
Hi..
You need to use $_FILES (
http://php.net/manual/pt_BR/reserved.variables.files.php)
Regards,
Jônatas Zechim
Thanks guys.
Donovan
--
D Brooke
--- End Message ---
--- Begin Message ---
Don't seem to be getting any feeds thru the newsgroup mirror(?).
--- End Message ---