php-general Digest 15 Jul 2011 14:59:48 -0000 Issue 7403
Topics (messages 314084 through 314092):
Re: Your language sucks because...
314084 by: George Langley
314085 by: Micky Hulse
314090 by: Richard Quadling
is_null() and is_string() reversed when using in switch case statements...
314086 by: Daevid Vincent
314087 by: Simon J Welsh
Re: is_null() and is_string() reversed when using in switch case statements...
[SOLVED]
314088 by: Daevid Vincent
314092 by: Jim Lucas
Re: problem with session_write_close
314089 by: Tamara Temple
A perfect example of tmesis. Was: Re: [PHP-DEV] deprecating ext/mysql
314091 by: Richard Quadling
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 ---
----- Original Message -----
From: Micky Hulse <rgmi...@gmail.com>
> On Thu, Jul 14, 2011 at 4:02 AM, Richard Quadling
> <rquadl...@gmail.com> wrote:
> > My daughter (6 or 7 at the time) came up with T, M and E. I was
> > abso-bloody-lutely amazed she managed to find a word starting
> with T,
> > M and E.
>
> What was the word?
--------------
He gave you a beautiful hint:
tmesis |təˈmēsis|
noun ( pl. -ses |-sēz|)
the separation of parts of a compound word by an intervening word or words,
heard mainly in informal speech (e.g., a whole nother story; shove it back
any-old-where in the pile).
ORIGIN mid 16th cent.: from Greek tmēsis ‘cutting,’ from temnein ‘to cut.’
George
--- End Message ---
--- Begin Message ---
On Thu, Jul 14, 2011 at 4:19 PM, George Langley <george.lang...@shaw.ca> wrote:
> He gave you a beautiful hint:
:: slaps self on forehead ::
I should've known!!! :D
Thanks!
Micky
--- End Message ---
--- Begin Message ---
On 15 July 2011 01:42, Micky Hulse <rgmi...@gmail.com> wrote:
> On Thu, Jul 14, 2011 at 4:19 PM, George Langley <george.lang...@shaw.ca>
> wrote:
>> He gave you a beautiful hint:
>
> :: slaps self on forehead ::
>
> I should've known!!! :D
>
> Thanks!
> Micky
He he!
Well done. It's a great word. My wife and I really didn't think
anything started with "tme". I have yet to be in a position to use it
in normal conversation.
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
--- End Message ---
--- Begin Message ---
Can someone double check me here, but I think I found a bug...
<?php
/*
$ php -v
PHP 5.3.6 with Suhosin-Patch (cli) (built: Apr 28 2011 14:20:48)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans
*/
function test($v)
{
var_dump($v);
if (is_string($v)) echo "FOUND A STRING.\n";
if (is_null($v)) echo "FOUND A NULL.\n";
switch ($v)
{
case is_string($v):
echo "I think v is a string, so this is broken.\n";
break;
case is_null($v):
echo "I think v is null, so this is broken.\n";
break;
case is_object($v):
$v = '{CLASS::'.get_class($v).'}';
echo "I think v is a class $v\n";
break;
case is_bool($v):
$v = ($v) ? '{TRUE}' : '{FALSE}';
echo "I think v is boolean $v\n";
break;
case is_array($v):
$v = '['.implode(',',$v).']';
echo "I think v is an array $v\n";
break;
case is_numeric($v):
echo "I think v is a number $v\n";
break;
}
}
class SomeClass {}
test('');
test(null);
test(new SomeClass());
test(true);
test(69);
test(array(1,2,3,4,5));
/*
Output will be:
string '' (length=0)
FOUND A STRING. I think v is null, so this is broken.
null
FOUND A NULL. I think v is a string, so this is broken.
object(SomeClass)[1]
I think v is a class {CLASS::SomeClass}
boolean true
I think v is boolean {TRUE}
int 69
I think v is a number 69
array
0 => int 1
1 => int 2
2 => int 3
3 => int 4
4 => int 5
I think v is an array [1,2,3,4,5]
*/
?>
--- End Message ---
--- Begin Message ---
On 15/07/2011, at 1:58 PM, Daevid Vincent wrote:
> function test($v)
> {
> var_dump($v);
>
> if (is_string($v)) echo "FOUND A STRING.\n";
> if (is_null($v)) echo "FOUND A NULL.\n";
>
> switch ($v)
> {
> case is_string($v):
> echo "I think v is a string, so this is broken.\n";
> break;
> case is_null($v):
> echo "I think v is null, so this is broken.\n";
> break;
> case is_object($v):
> $v = '{CLASS::'.get_class($v).'}';
> echo "I think v is a class $v\n";
> break;
>
> case is_bool($v):
> $v = ($v) ? '{TRUE}' : '{FALSE}';
> echo "I think v is boolean $v\n";
> break;
> case is_array($v):
> $v = '['.implode(',',$v).']';
> echo "I think v is an array $v\n";
> break;
> case is_numeric($v):
> echo "I think v is a number $v\n";
> break;
> }
> }
In both cases, $v is equivalent to false, so is_string(NULL) = false == NULL ==
$v, likewise for is_null($v);
You're most likely after switch(true) { … } rather than switch($v)
---
Simon Welsh
Admin of http://simon.geek.nz/
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Simon J Welsh [mailto:si...@welsh.co.nz]
> Sent: Thursday, July 14, 2011 7:29 PM
> To: Daevid Vincent
> Cc: php-gene...@lists.php.net
> Subject: Re: [PHP] is_null() and is_string() reversed when using in switch
> case statements...
>
> On 15/07/2011, at 1:58 PM, Daevid Vincent wrote:
>
> > function test($v)
> > {
> > var_dump($v);
> >
> > if (is_string($v)) echo "FOUND A STRING.\n";
> > if (is_null($v)) echo "FOUND A NULL.\n";
> >
> > switch ($v)
> > {
> > case is_string($v):
> > echo "I think v is a string, so this is broken.\n";
> > break;
> > case is_null($v):
> > echo "I think v is null, so this is broken.\n";
> > break;
> > case is_object($v):
> > $v = '{CLASS::'.get_class($v).'}';
> > echo "I think v is a class $v\n";
> > break;
> >
> > case is_bool($v):
> > $v = ($v) ? '{TRUE}' : '{FALSE}';
> > echo "I think v is boolean $v\n";
> > break;
> > case is_array($v):
> > $v = '['.implode(',',$v).']';
> > echo "I think v is an array $v\n";
> > break;
> > case is_numeric($v):
> > echo "I think v is a number $v\n";
> > break;
> > }
> > }
>
> In both cases, $v is equivalent to false, so is_string(NULL) = false ==
NULL
> == $v, likewise for is_null($v);
>
> You're most likely after switch(true) { . } rather than switch($v)
> ---
> Simon Welsh
> Admin of http://simon.geek.nz/
Ah! Thanks Simon! That is exactly right. Doh! I should have thought of
that... *smacks head*
Here is the fruit of my labor (and your fix)...
/**
* Useful for debugging functions to see parameter names, etc.
* Based upon http://www.php.net/manual/en/function.func-get-args.php#103296
*
* function anyfunc($arg1, $arg2, $arg3)
* {
* debug_func(__FUNCTION__, '$arg1, $arg2, $arg3', func_get_args());
* //do useful non-debugging stuff
* }
*
* @access public
* @return string
* @param string $function_name __FUNCTION__ of the root function as
passed into this function
* @param string $arg_names the ',,,' encapsulated parameter list of
the root function
* @param array $arg_vals the result of func_get_args() from the root
function passed into this function
* @param boolean $show_empty_params (FALSE)
* @author Daevid Vincent
* @date 2011-17-14
* @see func_get_args(), func_get_arg(), func_num_args()
*/
function debug_func($function_name, $arg_names, $arg_vals,
$show_empty_params=FALSE)
{
$params = array();
echo $function_name.'(';
$arg_names_array = explode(',', $arg_names);
//var_dump($arg_names, $arg_names_array, $arg_vals );
foreach($arg_names_array as $k => $parameter_name)
{
$v = $arg_vals[$k];
//echo "k = $parameter_name = $k and v = arg_vals[k] = $v<br>\n";
switch(true)
{
case is_string($v): if ($show_empty_params) $v = "'".$v."'"
; break;
case is_null($v): if ($show_empty_params) $v = '{NULL}';
break;
case is_bool($v): $v = ($v) ? '{TRUE}' : '{FALSE}'; break;
case is_array($v): (count($v) < 10) ? $v =
'['.implode(',',$v).']' : $v = '[ARRAY]'; break;
case is_object($v): $v = '{CLASS::'.get_class($v).'}';
break;
case is_numeric($v): break;
}
if ($show_empty_params || $v) $params[$k] = trim($parameter_name).':
'.$v;
}
echo implode(', ',$params).")<br/>\n";
}
--- End Message ---
--- Begin Message ---
On 7/14/2011 7:44 PM, Daevid Vincent wrote:
> Ah! Thanks Simon! That is exactly right. Doh! I should have thought of
> that... *smacks head*
>
> Here is the fruit of my labor (and your fix)...
>
> /**
> * Useful for debugging functions to see parameter names, etc.
> * Based upon http://www.php.net/manual/en/function.func-get-args.php#103296
> *
> * function anyfunc($arg1, $arg2, $arg3)
> * {
> * debug_func(__FUNCTION__, '$arg1, $arg2, $arg3', func_get_args());
> * //do useful non-debugging stuff
> * }
> *
> * @access public
> * @return string
> * @param string $function_name __FUNCTION__ of the root function as
> passed into this function
> * @param string $arg_names the ',,,' encapsulated parameter list of
> the root function
> * @param array $arg_vals the result of func_get_args() from the root
> function passed into this function
> * @param boolean $show_empty_params (FALSE)
> * @author Daevid Vincent
> * @date 2011-17-14
> * @see func_get_args(), func_get_arg(), func_num_args()
> */
> function debug_func($function_name, $arg_names, $arg_vals,
> $show_empty_params=FALSE)
> {
> $params = array();
> echo $function_name.'(';
> $arg_names_array = explode(',', $arg_names);
> //var_dump($arg_names, $arg_names_array, $arg_vals );
> foreach($arg_names_array as $k => $parameter_name)
> {
> $v = $arg_vals[$k];
> //echo "k = $parameter_name = $k and v = arg_vals[k] = $v<br>\n";
> switch(true)
> {
> case is_string($v): if ($show_empty_params) $v = "'".$v."'"
> ; break;
> case is_null($v): if ($show_empty_params) $v = '{NULL}';
> break;
> case is_bool($v): $v = ($v) ? '{TRUE}' : '{FALSE}'; break;
> case is_array($v): (count($v) < 10) ? $v =
> '['.implode(',',$v).']' : $v = '[ARRAY]'; break;
> case is_object($v): $v = '{CLASS::'.get_class($v).'}';
> break;
> case is_numeric($v): break;
> }
>
> if ($show_empty_params || $v) $params[$k] = trim($parameter_name).':
> '.$v;
> }
> echo implode(', ',$params).")<br/>\n";
> }
>
>
>
Can you give an example of where this might be useful?
Jim Lucas
--- End Message ---
--- Begin Message ---
I'm having a problem with a brand new installation of pmwiki. I've not
encountered this before so I'm unsure why this is happening. The
following two warnings are presented at the top of each page:
Warning: session_write_close() [function.session-write-close]: open(/
var/lib/php/session/sess_sh3dvs4pgiuq04vmj1tfmkqvj1, O_RDWR) failed:
Permission denied (13) in/var/www/vhosts/mouseha.us/httpdocs/
pmwiki-2.2.27/pmwiki.php on line 2012
Warning: session_write_close() [function.session-write-close]: Failed
to write session data (files). Please verify that the current setting
of session.save_path is correct (/var/lib/php/session) in/var/www/
vhosts/mouseha.us/httpdocs/pmwiki-2.2.27/pmwiki.php on line 2012
There are plenty of other session files in that directory with the
owner/group apache:apache. I don't know why it can't deal with this.
(Cross-posted between pmwiki-users and php-general.)
Update: I found out what was happening -- nothing to do with php in
general. My lovely server management software (Plesk) has started
adding a new line to it's vhost http include file:
SuexecUserGroup mouse psacln
which means apache is running under the local user/group for
permissions. The file in question above was left over from a previous
incarnation of the site (I blew it away and recreated it to start
fresh - hah!) so the session file was left over from the previous
session (not at all clear why it didn't get a new one) and had the
wrong permissions set. Resetting the permissions solved the problem.
--- End Message ---
--- Begin Message ---
On 15 July 2011 02:41, Larry Garfield <la...@garfieldtech.com> wrote:
> A-frickin'-men! :-)
--
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea
--- End Message ---