php-general Digest 10 May 2009 04:43:00 -0000 Issue 6113
Topics (messages 292416 through 292430):
intval
292416 by: kranthi
292417 by: Robert Cummings
292419 by: kranthi
292420 by: Robert Cummings
292421 by: kranthi
292423 by: Robert Cummings
292425 by: kranthi
Re: [email protected], Tim-Hinnerk Heuer has invited you to open a
Google mail account
292418 by: Lenin
292426 by: ×× ××× ×× ××
292427 by: Lenin
Something I don't understand about PHP classes
292422 by: Cesco
292424 by: Robert Cummings
292430 by: chetan rane
Re: Session data files
292428 by: phphelp -- kbk
Trying to create a colortable - what am I missing here?
292429 by: ×× ××× ×× ××
Administrivia:
To subscribe to the digest, e-mail:
[email protected]
To unsubscribe from the digest, e-mail:
[email protected]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Hi,
var_dump($_POST['month'], intval($_POST['month']), $_POST['month'] ==
((int)($_POST['month']));
var_dump($_POST['month'], intval($_POST['month']), $_POST['month'] ==
(intval($_POST['month'])));
is giving me
string(3) "Jan" int(0) bool(true)
but i m expecting
string(3) "Jan" int(0) bool(false)
ny ideas y this is happening??
Kranthi.
--- End Message ---
--- Begin Message ---
On Sat, 2009-05-09 at 18:22 +0530, kranthi wrote:
> var_dump($_POST['month'], intval($_POST['month']), $_POST['month'] ==
> ((int)($_POST['month']));
> var_dump($_POST['month'], intval($_POST['month']), $_POST['month'] ==
> (intval($_POST['month'])));
After I fixed your syntax error this worked fine for me in PHP 5.2.9:
string(3) "Jan"
int(0)
bool(true)
string(3) "Jan"
int(0)
bool(true)
<?php
$_POST['month'] = 'Jan';
var_dump( $_POST['month'], intval( $_POST['month'] ), $_POST['month'] ==
(int)$_POST['month'] );
var_dump( $_POST['month'], intval( $_POST['month'] ), $_POST['month'] ==
intval( $_POST['month'] ) );
?>
Your use of parenthesis shows you lack understanding of operator and
function use. All those parenthesis generally make things less readable
despite your best intentions to clarify the process.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
thanks for the reply... just happened to see http://php.net/ternary
which explains the above result
i want to explicitly type cast all the numbers passed via post (by
default they are strings)
is_numeric() is a option, but it will not be possible to differentiate
between int and float.
$_POST['month'] !== (string)(int)$_POST['month']
this is exactly what i want... but wont this take up memory when used
with array_walk_recursive() ?
--- End Message ---
--- Begin Message ---
On Sat, 2009-05-09 at 20:02 +0530, kranthi wrote:
> thanks for the reply... just happened to see http://php.net/ternary
> which explains the above result
>
> i want to explicitly type cast all the numbers passed via post (by
> default they are strings)
> is_numeric() is a option, but it will not be possible to differentiate
> between int and float.
>
> $_POST['month'] !== (string)(int)$_POST['month']
> this is exactly what i want... but wont this take up memory when used
> with array_walk_recursive() ?
Just add the value to 0 and PHP will do the juggling for you:
<?php
$_POST = array( '1', '100', '100.1', '100.123' );
foreach( $_POST as $value )
{
$value = 0 + $value;
echo 'Value: ';
var_dump( $value );
}
?>
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
k i ended up with this code....
<?php
$_POST = array( '1', '100', '100.1', '100.123', 'a');
foreach( $_POST as &$value )
{
if(is_numeric($value)) {
$value = $value + 0;
}
}
var_dump($_POST);
?>
its giving me
array(5) { [0]=> int(1) [1]=> int(100) [2]=> float(100.1) [3]=>
float(100.123) [4]=> &string(1) "a" }
what does &string mean ??
--- End Message ---
--- Begin Message ---
On Sat, 2009-05-09 at 21:23 +0530, kranthi wrote:
> k i ended up with this code....
>
> <?php
>
> $_POST = array( '1', '100', '100.1', '100.123', 'a');
>
> foreach( $_POST as &$value )
> {
> if(is_numeric($value)) {
> $value = $value + 0;
> }
> }
> var_dump($_POST);
>
> ?>
>
> its giving me
> array(5) { [0]=> int(1) [1]=> int(100) [2]=> float(100.1) [3]=>
> float(100.123) [4]=> &string(1) "a" }
> what does &string mean ??
Maybe because you assigned values from $_POST to $value with the reference
operator?
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
if that is the case & should appear before all the other variables as well....
and.....
<?php
function foo(&$val, $key) {
if(is_numeric($value)) {
$value = $value + 0;
}
}
$_POST = array( '1', '100', '100.1', '100.123', 'a');
array_walk_recursive($_POST, 'foo');
var_dump($_POST);
?>
is giving me
array(5) { [0]=> int(1) [1]=> int(100) [2]=> float(100.1) [3]=>
float(100.123) [4]=> string(1) "a" }
ny idea y this difference arises?
--- End Message ---
--- Begin Message ---
Hahaha quite Hilarious.
[email protected] is also hosted by Google Apps :P
Its the Largest active PHP group in South Asia (originated from Bangladesh).
Participated by thousands from many other countries.
Keep the humor on! :D
--- End Message ---
--- Begin Message ---
That's how you help information-monster-privacy-killing-companies to gain
more control...
You use GMail? ever visited blogspot? search on Google? Visit half of the
leading sites of the world (since they have Google Analytics) or visit the
other half that have Google Adsense or both of them?
Maybe you use Google Chrome? Google Earth? Google Desktop? Android? Google
_____?
You think that it? now it aims for you, the programmers. Use the "nice"
Google AJAX API? so comfortable, lightweight....
Yes, now Google can collect MORE information.
Yes? thank you by helping Google. if you use Google softwares, please click
CTRL+ALT+DELETE, go to proccess, look for GoogleUpdate.exe and wonder why is
it there? oh, now you remember? use Google Earth/Desktop/.... ?
Thank you for helping Google in another step for becoming an
"information-monster".
If anyone wants - I made a presentation about Privacy and how Google
infiltrates your privacy.
(I know someone will smile and say "but hey - you use Gmail". I'll just
smile back and say that using gmail isn't "bad" - but using Google all the
time IS bad).
Watch how many large organizations have protested about Google "way" (of
tracking you, as individiual, for over 18 months).
Now someone again will "point" that "What do I mind if they are following
me? I am not doing anything illegal".
No, I am not saying the government will "use this information" - The FBI
have asked all search engines to give him data about searches that might
relate to criminal activities. they all gave. Except Google.
What do they do with this information? Google Adsense, Analytics, News,
Search, Images, API, Code.....
Blogspot, Adwords, should I continue this list of Google products that I am
sure that each one of you was exposed to?
On Sat, May 9, 2009 at 12:27 AM, Lenin <[email protected]> wrote:
> Yeah gmail is a nice thing :)
>
> The best ever mailing system world has ever seen until now.
>
--
Use ROT26 for best security
--- End Message ---
--- Begin Message ---
LOL good points indeed!
But I dont use other Google products that much. But yes I'm helping google
in some way.
One great satisfaction I have is I use Ubuntu with FireFox. :)
--- End Message ---
--- Begin Message ---
Ok, I suppose that this should be a very simple problem and probably
the answer is obvious, but I really can't understand how the classes
and the rest of the stuff works in PHP...
Let's suppose that we have this piece of code:
<?php
class Duck {
function __construct() {
while(1==1) {
// This is an infinite loop
}
}
}
echo "Hello world...";
$DonaldDuck = new Duck();
?>
I have put an infinite loop in the class constructor just to introduce
a problem that will halt the execution of the PHP code.
Now, If I run this code I would expect that the PHP interpreter would
print the "Hello world..." string, and then it should call the class
constructor with the infinite loop inside of it.
But that doesn't happen.
Instead, the PHP interpreter enters IMMEDIATELY into an infinite loop,
as if the variables were declared immediately and then the rest of the
code is executed.
Is it right? Because I'm having really hard times in debugging a PHP
class
--- End Message ---
--- Begin Message ---
On Sat, 2009-05-09 at 18:35 +0200, Cesco wrote:
> Ok, I suppose that this should be a very simple problem and probably
> the answer is obvious, but I really can't understand how the classes
> and the rest of the stuff works in PHP...
>
> Let's suppose that we have this piece of code:
>
>
> <?php
>
> class Duck {
>
> function __construct() {
>
> while(1==1) {
> // This is an infinite loop
> }
>
> }
> }
>
> echo "Hello world...";
> $DonaldDuck = new Duck();
>
> ?>
>
>
> I have put an infinite loop in the class constructor just to introduce
> a problem that will halt the execution of the PHP code.
>
> Now, If I run this code I would expect that the PHP interpreter would
> print the "Hello world..." string, and then it should call the class
> constructor with the infinite loop inside of it.
>
> But that doesn't happen.
>
> Instead, the PHP interpreter enters IMMEDIATELY into an infinite loop,
> as if the variables were declared immediately and then the rest of the
> code is executed.
>
> Is it right? Because I'm having really hard times in debugging a PHP
> class
Presumably you're doing this on the shell (versus in a web page). You
need to send the newline ("\n") character since most terminals buffer
the output until a newline character is encountered. If htis is a
webpage you are in for even more trouble since browser often won't
output anything until they receive at least X bytes (where X depends on
the browser).
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
Hi
you can use the following code
<?php
class Duck {
function __construct() {
while(1==1) {
// This is an infinite loop
}
}
}
echo "Hello world...";
flush();
$DonaldDuck = new Duck();
?>
On Sat, May 9, 2009 at 10:16 PM, Robert Cummings <[email protected]>wrote:
> On Sat, 2009-05-09 at 18:35 +0200, Cesco wrote:
> > Ok, I suppose that this should be a very simple problem and probably
> > the answer is obvious, but I really can't understand how the classes
> > and the rest of the stuff works in PHP...
> >
> > Let's suppose that we have this piece of code:
> >
> >
> > <?php
> >
> > class Duck {
> >
> > function __construct() {
> >
> > while(1==1) {
> > // This is an infinite loop
> > }
> >
> > }
> > }
> >
> > echo "Hello world...";
> > $DonaldDuck = new Duck();
> >
> > ?>
> >
> >
> > I have put an infinite loop in the class constructor just to introduce
> > a problem that will halt the execution of the PHP code.
> >
> > Now, If I run this code I would expect that the PHP interpreter would
> > print the "Hello world..." string, and then it should call the class
> > constructor with the infinite loop inside of it.
> >
> > But that doesn't happen.
> >
> > Instead, the PHP interpreter enters IMMEDIATELY into an infinite loop,
> > as if the variables were declared immediately and then the rest of the
> > code is executed.
> >
> > Is it right? Because I'm having really hard times in debugging a PHP
> > class
>
> Presumably you're doing this on the shell (versus in a web page). You
> need to send the newline ("\n") character since most terminals buffer
> the output until a newline character is encountered. If htis is a
> webpage you are in for even more trouble since browser often won't
> output anything until they receive at least X bytes (where X depends on
> the browser).
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Have A pleasant Day
Chetan. D. Rane
Location: India
Contact: +91-9986057255
other ID: [email protected]
[email protected]
--- End Message ---
--- Begin Message ---
Thanks, Tom - -
On May 8, 2009, at 12:37 PM, Tom Worster wrote:
On 5/8/09 11:09 AM, "phphelp -- kbk" <[email protected]> wrote:
Just something I'm curious about: When I run PHP on my development
box (W2K), I just get one session file per connection which gets
deleted (usually) after the session expires.
When I look at the session files on the client server (linux/apache),
there seems to be one session file per page click. I needed to clear
them a few minutes ago, and there are already 80+ files, and this is
just from one user (a tester -- this is in late-late-late beta).
Now, there is nothing wrong -- everything is working fine -- I am
just curious if Apache does this differently, or if there is a
configuration setting that governs this (I haven't found -- but only
did a cursory look).
Anybody willing to take the time to enlighten me?
have you satisfied yourself that what you're seeing is not just an
artifact
of how the session garbage collector works?
http://us.php.net/manual/en/session.configuration.php
maybe compare the gc parameters on the two different machines?
phpinfo()
displays the values.
--- End Message ---
--- Begin Message ---
I've tried to make a color table, but I am missing something. not in the
color-table-code itself, but in somewhere else... I just can't find...
error_reporting is E_ALL, running it on my local server, the script has
512MB to spend, no errors occurs - just something, is wrong.
(4072 * 4072 ~= 255*255*255)
The problem is that the result image only contains all the blue(0,0,0 |
0,0,1 | 0,0,2 ............. 0,0,255) and the rest is black.
I've tried anything, did echo "X{$i % 4072}Y{LONG_Y_CODE}:{$r}-{$g}-{$b}\n";
All seems to be correct, what am I missing here? PHP 5.2.8
$im = imagecreate(4072, 4073);
$white = imagecolorallocate($im, 0, 0, 0);
$r = $g = $b = $i = 0;
$max = 255;
while ($r <= $max) {
while ($g <= $max) {
while ($b <= $max) {
$n = imagecolorallocate($im, $r, $g, $b);
imagesetpixel($im, ($i % 4072), (($i - ($i % 4072)) / 4072),
$n);
$i++;
$b++;
}
$b = 0;
$g++;
}
$g = 0;
$r++;
}
header("Content-Type: image/png");
imagepng($im);
imagedestroy($im);
--
Use ROT26 for best security
--- End Message ---