php-general Digest 15 Jun 2012 01:16:16 -0000 Issue 7854
Topics (messages 318232 through 318243):
Re: global array
318232 by: marco.behnke.biz
318233 by: Jeff Burcher
318236 by: Jim Giner
318237 by: Al
318239 by: Jim Giner
318240 by: Ashley Sheridan
318241 by: Jim Giner
Re: how to walk async recursively over an object, doing work (in right order)
per leaf
318234 by: rene7705
318235 by: rene7705
add one day to DateTime based on timestamp
318238 by: Shailesh N. Humbad
php form action breaks script
318242 by: Tim Dunphy
318243 by: David Robley
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 ---
Jeff Burcher <j...@allredmetal.com> hat am 14. Juni 2012 um 13:55 geschrieben:
>
> function Part_BOM($PartID, $need, $phase) {
>
>
>
> global $Invreq;
uppercase R !!!
And much better is adding it as another parameter and inject it:
function Part_BOM($PartID, $need, $phase, $InvReq) {
....
}
// call it
Part_BOM(..., ..., ..., $InvReq);
And please read about foreach() and what you can do with it.
--- End Message ---
--- Begin Message ---
You're a genius!! Thank you. Uppercase 'R', sheesh. PHP is sooo picky. I worked
for two days trying to figure that one out. Anyway, for future reference, you
can pass the entire array as a variable like that?? and do you know if the '+='
statement will create an array entry if one doesn't exist?
Thanks,
Jeff Burcher - IT Dept
Allred Metal Stamping
PO Box 2566
High Point, NC 27261
(336)886-5221 x229
j...@allredmetal.com
> -----Original Message-----
> From: ma...@behnke.biz [mailto:ma...@behnke.biz]
> Sent: Thursday, June 14, 2012 8:04 AM
> To: php-gene...@lists.php.net; j...@allredmetal.com
> Subject: Re: [PHP] global array
>
>
>
>
> Jeff Burcher <j...@allredmetal.com> hat am 14. Juni 2012 um 13:55
> geschrieben:
>
> >
> > function Part_BOM($PartID, $need, $phase) {
> >
> >
> >
> > global $Invreq;
>
>
> uppercase R !!!
> And much better is adding it as another parameter and inject it:
>
> function Part_BOM($PartID, $need, $phase, $InvReq) { ....
> }
>
> // call it
> Part_BOM(..., ..., ..., $InvReq);
>
> And please read about foreach() and what you can do with it.
>
> --
> PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Yes - PHP is very picky. Hence I never capitalize anything! I use
underscores to make varnames more understandable, as in $inv_req
--- End Message ---
--- Begin Message ---
On 6/14/2012 12:49 PM, Jim Giner wrote:
Yes - PHP is very picky. Hence I never capitalize anything! I use
underscores to make varnames more understandable, as in $inv_req
There is another nice custom e.g. $invReg it's easy to read and it doesn't
conflict with PHP syntax for some functions e.g., in_aray(). and defines
DOCUMENT_ROOT
--- End Message ---
--- Begin Message ---
"Al" <n...@ridersite.org> wrote in message
news:6b.c0.39100.4ef1a...@pb1.pair.com...
>
>
> On 6/14/2012 12:49 PM, Jim Giner wrote:
>> Yes - PHP is very picky. Hence I never capitalize anything! I use
>> underscores to make varnames more understandable, as in $inv_req
>>
>>
>
> There is another nice custom e.g. $invReg it's easy to read and it doesn't
> conflict with PHP syntax for some functions e.g., in_aray(). and defines
> DOCUMENT_ROOT
And what is that custom?
--- End Message ---
--- Begin Message ---
On Thu, 2012-06-14 at 15:13 -0400, Jim Giner wrote:
> "Al" <n...@ridersite.org> wrote in message
> news:6b.c0.39100.4ef1a...@pb1.pair.com...
> >
> >
> > On 6/14/2012 12:49 PM, Jim Giner wrote:
> >> Yes - PHP is very picky. Hence I never capitalize anything! I use
> >> underscores to make varnames more understandable, as in $inv_req
> >>
> >>
> >
> > There is another nice custom e.g. $invReg it's easy to read and it doesn't
> > conflict with PHP syntax for some functions e.g., in_aray(). and defines
> > DOCUMENT_ROOT
>
> And what is that custom?
>
>
>
I think he means camelCase naming syntax. It does tend to involve fewer
keystrokes and results in shorter names that might more easily fit to a
screen or paper, but I have to say I prefer the underscore convention,
it just makes things much more readable (which is probably why built-in
PHP functions and constants use it)
--
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
See - I didn't even notice he used camel-case - I thought he typed the same
thing that got the OP in trouble. See how difficult that custom is? That's
why for any case sensitive syntax, I stick to all lower case to avoid just
that kind of bug-a-boo.
--- End Message ---
--- Begin Message ---
I think I've got it figured out now..
My solution is to async build up a flat list of items (from the
recursive object) to process first, then do another async loop (which
I'll build soon) to do the work per item, and when that's done,
replace the placeholder with the result.
This code works on a custom datastructure that looks like this;
{
hmData : {
mijnDataA : 'a',
mijnDataB : 'b',
mijnSubKeyA : {
hmData : {
mijnDataX : 'x'
},
hmSettings : {
// app-specifc values for the object with key 'mijnDataX'
}
}
},
hmSettings : {
// app-specific values for the object with keys 'mijnDataA',
'mijnDataB', and 'mijnSubKeyA'
}
}
Then, the actual code to build up a flat work list of this recursive
array, up to a certain level deep (levelsAtOnce) is;
printNextLevel : function (pvCmd) {
if (
typeof pvCmd.val == 'object'
&& typeof pvCmd.val.hmStats == 'object'
&& typeof pvCmd.val.hmData == 'object'
) {
//if (pvCmd.keyValueName &&
pvCmd.keyValueName!='')
pvCmd.val.hmStats.keyValueName=pvCmd.keyValueName; //bit of a hack, i
agree.
var td = typeof pvCmd.val.hmData;
var d = pvCmd.val.hmData;
} else {
var td = typeof pvCmd.val;
var d = pvCmd.val;
};
rajmv.hms.tools.printNextLevel_scan (pvCmd,
rajmv.hms.tools.printNextLevel_buildDatanodes);
return {
html : '<tr><td>Have Yet To Render
This</td></tr>'
};
},
printNextLevel_scan : function (pvCmd, callback) {
if (!pvCmd.scanResults) {
pvCmd.scanResults = [{level:1,
datanode:pvCmd.scanPointer}];
pvCmd.scanIdx = 0;
pvCmd.scanCount = 0;
pvCmd.lastPause = 0;
pvCmd.scanCallback = callback;
}
rajmv.hms.tools.printNextLevel_scanItem (pvCmd);
pvCmd.scanCount++;
//rajmv.log (2, 'pvCmd.scanIdx='+pvCmd.scanIdx+',
scanResults.length-1='+(pvCmd.scanResults.length-1));
if (pvCmd.scanIdx==pvCmd.scanResults.length-1) {
if (typeof pvCmd.scanCallback=='function') {
pvCmd.scanCallback (pvCmd);
}
return true; // scanning done!
}
var pauseFactor = pvCmd.scanCount / 7;
if (pauseFactor > pvCmd.lastPause + 1) {
setTimeout (function () {
pvCmd.lastPause = pauseFactor;
rajmv.hms.tools.printNextLevel_scan(pvCmd);
}, 50);
} else {
rajmv.hms.tools.printNextLevel_scan(pvCmd);
};
return false; // not done yet
},
printNextLevel_scanItem : function (pvCmd) {
var it = pvCmd.scanResults[pvCmd.scanIdx];
if (!it || !it.datanode) return false;
var tit = typeof it.datanode;
if (tit=='object' && it.datanode!==null &&
it.datanode!==undefined) {
if (!it.keys && it.level<=pvCmd.levelsAtOnce) {
it.keys = Object.keys (it.datanode);
it.keyIdx = 0;
}
}
if (it.keys) {
if (it.keyIdx<it.keys.length) {
var doUntil = it.keyIdx+20;
while (it.keyIdx<doUntil &&
it.keyIdx<it.keys.length-1) {
rajmv.hms.tools.printNextLevel_scanKey (pvCmd);
it.keyIdx++;
pvCmd.scanCount++;
if
(it.keyIdx==it.keys.length-1) {
pvCmd.scanIdx++;
pvCmd.scanCount++;
}
var pauseFactor =
pvCmd.scanCount / 7;
if (pauseFactor >
pvCmd.lastPause + 1) break;
}
}
} else {
pvCmd.scanIdx++;
pvCmd.scanCount++;
}
},
printNextLevel_scanKey : function (pvCmd) {
var it = pvCmd.scanResults[pvCmd.scanIdx];
if (!it.keys[it.keyIdx]) debugger;
pvCmd.scanResults.splice(pvCmd.scanIdx+1, 0,
{level:it.level+1,
datanode:it.datanode[it.keys[it.keyIdx]].hmData}); // insert next
datanode just after the scanIdx
rajmv.log (2, 'hms.tools.printNextLevel_scanKey():
pvCmd.scanCount='+pvCmd.scanCount);
},
printNextLevel_buildDatanodes : function (pvCmd) {
if (!pvCmd.html) pvCmd.html = '';
// this is where the flat list is ready to be processed
(into HTML
in my case);
debugger;
},
--- End Message ---
--- Begin Message ---
oops; printNextLevel : function (pvCmd) {
if (
typeof pvCmd.val == 'object'
&& typeof pvCmd.val.hmStats == 'object'
&& typeof pvCmd.val.hmData == 'object'
) {
//if (pvCmd.keyValueName && pvCmd.keyValueName!='')
pvCmd.val.hmStats.keyValueName=pvCmd.keyValueName; //bit of a hack, i
agree.
var td = typeof pvCmd.val.hmData;
var d = pvCmd.val.hmData;
} else {
var td = typeof pvCmd.val;
var d = pvCmd.val;
};
pvCmd.scanPointer = d;
rajmv.hms.tools.printNextLevel_scan (pvCmd,
rajmv.hms.tools.printNextLevel_buildDatanodes);
return {
html : '<tr><td>Have Yet To Render This</td></tr>'
};
},
--- End Message ---
--- Begin Message ---
Hello,
When I create a DateTime object from a UNIX timestamp, and then add a
one day interval, PHP adds 25 hours instead of 24. Is this a bug, or
something to do with the time zones?
Here are the commands I'm running from my shell:
----------
$ date
Wed Jun 13 06:08:24 PDT 2012
$ php -r '$d=new DateTime("@1082444400"); print $d->format("r")."\n";
$d->add(new DateInterval("P1D")); print $d->format("r")."\n";'
Tue, 20 Apr 2004 07:00:00 +0000
Wed, 21 Apr 2004 08:00:00 +0000
----------
If I set the time zone on the new DataTime object to America/Los_Angeles
before adding the 1 day period, then it works as expected.
----------
$ php -r '$d=new DateTime("@1082444400"); $d->setTimeZone(new
DateTimeZone("America/Los_Angeles")); print $d->format("r")."\n";
$d->add(new DateInterval("P1D")); print $d->format("r")."\n";'
Tue, 20 Apr 2004 00:00:00 -0700
Wed, 21 Apr 2004 00:00:00 -0700
----------
Regards,
Shailesh
--- End Message ---
--- Begin Message ---
Hello list,
I was just wondering if I could get some opinions on a snippet of
code which breaks a php web page.
First the working code which is basically an html form being echoed by php:
if ($output_form) {
echo '<br /><br /><form action="sendemail.php>" method="post" >
<label for="subject">Subject of email:</label><br />
<input id="subject" name="subject" type="text" size="30" /><br />
<label for="elvismail">Body of email:</label><br />
<textarea id="elvismail" name="elvismail" rows="8"
cols="40"></textarea><br />
<input type="submit" name="Submit" value="Submit" />
</form>';
}
However if I change the form action to this, it breaks the page
resulting in a white screen of death:
if ($output_form) {
echo '<br /><br /><form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="post" >
<label for="subject">Subject of email:</label><br />
<input id="subject" name="subject" type="text" size="30" /><br />
<label for="elvismail">Body of email:</label><br />
<textarea id="elvismail" name="elvismail" rows="8"
cols="40"></textarea><br />
<input type="submit" name="Submit" value="Submit" />
</form>';
}
Reverting the one line to this:
echo '<br /><br /><form action="sendemail.php" method="post" >
gets it working again. Now I don't know if it's an unbalanced quote
mark or what's going on. But I'd appreciate any advice you may have.
Best,
tim
--
GPG me!!
gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
--- End Message ---
--- Begin Message ---
Tim Dunphy wrote:
> Hello list,
>
> I was just wondering if I could get some opinions on a snippet of
> code which breaks a php web page.
>
> First the working code which is basically an html form being echoed by
> php:
>
> if ($output_form) {
>
> echo '<br /><br /><form action="sendemail.php>" method="post" >
> <label for="subject">Subject of email:</label><br />
> <input id="subject" name="subject" type="text" size="30" /><br />
> <label for="elvismail">Body of email:</label><br />
> <textarea id="elvismail" name="elvismail" rows="8"
> cols="40"></textarea><br />
> <input type="submit" name="Submit" value="Submit" />
> </form>';
>
>
> }
>
> However if I change the form action to this, it breaks the page
> resulting in a white screen of death:
>
>
> if ($output_form) {
>
> echo '<br /><br /><form action="<?php echo $_SERVER['PHP_SELF']; ?>"
> method="post" >
> <label for="subject">Subject of email:</label><br />
> <input id="subject" name="subject" type="text" size="30" /><br />
> <label for="elvismail">Body of email:</label><br />
> <textarea id="elvismail" name="elvismail" rows="8"
> cols="40"></textarea><br />
> <input type="submit" name="Submit" value="Submit" />
> </form>';
>
>
> }
>
> Reverting the one line to this:
>
> echo '<br /><br /><form action="sendemail.php" method="post" >
>
> gets it working again. Now I don't know if it's an unbalanced quote
> mark or what's going on. But I'd appreciate any advice you may have.
>
>
> Best,
> tim
>
If you check your apache log you'll probably see an error message. But the
problem seems to be that your string you are trying to echo is enclosed in
single quotes, and contains a string in <?php tags. Try something like
echo '<br /><br /><form action="' . $_SERVER['PHP_SELF'] . '"
method="post"> ...etc
Cheers
--
David Robley
"I haven't had any tooth decay yet," said Tom precariously.
Today is Sweetmorn, the 20th day of Confusion in the YOLD 3178.
--- End Message ---