Re: [PHP] Variable Troubleshooting Code

2012-01-10 Thread Donovan Brooke

Jim Lucas wrote:
[snip]

if (!isset($pmatch) || substr($key,0,strlen($pmatch)) == $pmatch) {
print "$key = $value";
}


[snip]


I would change the above the the following:

if ( empty($pmatch) || ( strpos($key, $pmatch) === 0 ) ) {
print "$key = $value";
}

it would be slightly faster




love the "skin the cat" game!

What I like about this Jim is that the strpos() could be changed to 
allow a "contains" argument rather than a "begins with" argument...

for example if you wanted to find all variable names containing 'foo'.

Something like:


if ( empty($pmatch) || (( strpos($tkey, $pmatch) === 0 ) || ( 
strpos($tkey, $pmatch) > 0 ))) {

  print "$key = $value";
}

t_foo
foo_t
t_foo_t

would all be found.

Thanks!
Donovan





--
D Brooke

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



Re: [PHP] Variable Troubleshooting Code

2012-01-10 Thread Jim Lucas

On 01/09/2012 07:16 PM, Donovan Brooke wrote:

Just to share, a Mr. Harkness forwarded me a consolidated version of my
code.. basically substituting the innards for:


if (!isset($pmatch) || substr($key,0,strlen($pmatch)) == $pmatch) {
print "$key = $value";
}


Cheers,
Donovan





I would change the above the the following:

if ( empty($pmatch) || ( strpos($key, $pmatch) === 0 ) ) {
  print "$key = $value";
}

it would be slightly faster

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

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



Re: [PHP] Variable Troubleshooting Code

2012-01-09 Thread Donovan Brooke
Just to share, a Mr. Harkness forwarded me a consolidated version of my 
code.. basically substituting the innards for:



if (!isset($pmatch) || substr($key,0,strlen($pmatch)) == $pmatch) {
   print "$key = $value";
}


Cheers,
Donovan



--
D Brooke

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



Re: [PHP] Variable Troubleshooting Code

2012-01-09 Thread Paul M Foster
On Mon, Jan 09, 2012 at 10:42:59AM -0500, Marc Guay wrote:

> > some pretty natives php functions exists to do the job :
> 
> But how many times in my life will I have write echo ""; ???
> Does anyone have a handy solution? (Make this the default behavior?
> Add a "even more human-readable" flag to the function?  Create a
> simple macro in Aptana 3?)

I have an init file that I include in every site that contains a few
routines I use over and over. One such is:

function instrument($legend, $var)
{
print $legend . "\n";;
print "\n";
print_r($var);
print "\n";
}

I use this routine wherever I want to see what's going on. It formats
(particularly) array output so that I can read it, instead of having
everything look like JSON, which is much harder to read.

Feel free to use the above yourself as needed.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

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



Re: [PHP] Variable Troubleshooting Code

2012-01-09 Thread Ashley Sheridan


Ashley Sheridan  wrote:

>
>
>Marc Guay  wrote:
>
>>> some pretty natives php functions exists to do the job :
>>
>>But how many times in my life will I have write echo ""; ???
>>Does anyone have a handy solution? (Make this the default behavior?
>>Add a "even more human-readable" flag to the function?  Create a
>>simple macro in Aptana 3?)
>>
>>Argz,
>>Marc
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>
>I prefer car_dump with the xdebug module installed, the output is
>nicely formatted, which might be what you're looking for?
>
>Thanks,
>Ash
>http://ashleysheridan.co.uk
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

That should have been var_dump(), stupid phone auto correct!

Thanks,
Ash
http://ashleysheridan.co.uk

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



Re: [PHP] Variable Troubleshooting Code

2012-01-09 Thread Ashley Sheridan


Marc Guay  wrote:

>> some pretty natives php functions exists to do the job :
>
>But how many times in my life will I have write echo ""; ???
>Does anyone have a handy solution? (Make this the default behavior?
>Add a "even more human-readable" flag to the function?  Create a
>simple macro in Aptana 3?)
>
>Argz,
>Marc
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

I prefer car_dump with the xdebug module installed, the output is nicely 
formatted, which might be what you're looking for?

Thanks,
Ash
http://ashleysheridan.co.uk

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



Re: [PHP] Variable Troubleshooting Code

2012-01-09 Thread Marc Guay
> some pretty natives php functions exists to do the job :

But how many times in my life will I have write echo ""; ???
Does anyone have a handy solution? (Make this the default behavior?
Add a "even more human-readable" flag to the function?  Create a
simple macro in Aptana 3?)

Argz,
Marc

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



Re: [PHP] Variable Troubleshooting Code

2012-01-07 Thread David Courtin
Hi,

some pretty natives php functions exists to do the job :
var_export — Outputs or returns a parsable string representation of a variable
debug_zval_dump — Dumps a string representation of an internal zend value to 
output
var_dump — Dumps information about a variable
print_r — Prints human-readable information about a variable

echo '';
print_r( array | object );
echo '';  

Regards.


Le 7 janv. 2012 à 19:00, Donovan Brooke a écrit :

> Hello!,
> I work in another language mostly and often develop while displaying 
> variables (post,get,and defined) and their values at the bottom of the page 
> or in specific places. So, I thought I'd forward my PHP version as an effort 
> of good Karma to the list perhaps! ;-)
> 
> Below is 2 simple functions that are helpful for troubleshooting while 
> developing. Just place this code into a .php file and require it at the top 
> of any PHP page. Then, at the bottom of the page, or in a specific (more 
> pertinent) location, call the functions with something like this:
> 
> 
>  //troubleshooting code
> print 'Testing:';
>   
> print htmlentities(list_formvars());
>   
> print htmlentities(list_vars(get_defined_vars()));
>   
> print '';
> ?>
> -
> 
> Optionally, you can call only specific naming conventions of your variables 
> (if you use them).. ie:
> 
> print htmlentities(list_vars(get_defined_vars(),'t_'));
> 
> The above will display all defined vars such as:
> 
> t_name=
> t_city=
> t_address=
> 
> etc..
> 
> 
> Code:
> ---
> /*
> FUNCTION NAME: list_formvars
>   INPUT: optional  var
>   OUTPUT:  =  
>  =  
>   USE: For troubleshooting code
> 
>   Example Use:
>  list_formvars();
>  list_formvars('f_a');
> 
> */function list_formvars($pmatch = null) {
>   print "'get' Vars:";
>   foreach ($_GET as $key => $value) {
>if (isset($pmatch)) {
>   if (substr($key,0,strlen($pmatch)) == $pmatch) {
>  print "$key = $value";
>   }
>} else {
>   print "$key = $value";
>}
> }
> 
>   print "'post' Vars:";
>   foreach ($_POST as $key => $value) {
>if (isset($pmatch)) {
>   if (substr($key,0,strlen($pmatch)) == $pmatch) {
>  print "$key = $value";
>   }
>} else {
>   print "$key = $value";
>}
> }
> }/*
> FUNCTION NAME: list_vars
>   INPUT: get_defined_vars(), match
>   OUTPUT:  =  
>  =  
>   USE: For troubleshooting code
> 
>   Example Use:
>  list_vars(get_defined_vars());
>  list_vars(get_defined_vars(),'t_');
> */function list_vars($a_vars,$pmatch = null) {
>  print "'defined' Vars:";
> foreach ($a_vars as $key => $value) {
>if (isset($pmatch)) {
>   if (substr($key,0,strlen($pmatch)) == $pmatch) {
>  print "$key = $value";
>   }
>} else {
>   print "$key = $value";
>}
> }
> }
> 
> 
> Cheers,
> Donovan
> 
> 
> P.S. Always open to good criticism if you peeps see something that can be 
> written better.. this is about my 3rd PHP project only... so, still heavily 
> learning ;-)
> 
> 
> -- 
> D Brooke
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 



[PHP] Variable Troubleshooting Code

2012-01-07 Thread Donovan Brooke

Hello!,
I work in another language mostly and often develop while displaying 
variables (post,get,and defined) and their values at the bottom of the 
page or in specific places. So, I thought I'd forward my PHP version as 
an effort of good Karma to the list perhaps! ;-)


Below is 2 simple functions that are helpful for troubleshooting while 
developing. Just place this code into a .php file and require it at the 
top of any PHP page. Then, at the bottom of the page, or in a specific 
(more pertinent) location, call the functions with something like this:



Testing:';

print htmlentities(list_formvars());

print htmlentities(list_vars(get_defined_vars()));

print '';
?>
-

Optionally, you can call only specific naming conventions of your 
variables (if you use them).. ie:


print htmlentities(list_vars(get_defined_vars(),'t_'));

The above will display all defined vars such as:

t_name=
t_city=
t_address=

etc..


Code:
---
/*
FUNCTION NAME: list_formvars
   INPUT: optional  var
   OUTPUT:  =  
  =  
   USE: For troubleshooting code

   Example Use:
  list_formvars();
  list_formvars('f_a');

*/function list_formvars($pmatch = null) {
   print "'get' Vars:";
   foreach ($_GET as $key => $value) {
if (isset($pmatch)) {
   if (substr($key,0,strlen($pmatch)) == $pmatch) {
  print "$key = $value";
   }
} else {
   print "$key = $value";
}
 }

   print "'post' Vars:";
   foreach ($_POST as $key => $value) {
if (isset($pmatch)) {
   if (substr($key,0,strlen($pmatch)) == $pmatch) {
  print "$key = $value";
   }
} else {
   print "$key = $value";
}
 }
}/*
FUNCTION NAME: list_vars
   INPUT: get_defined_vars(), match
   OUTPUT:  =  
  =  
   USE: For troubleshooting code

   Example Use:
  list_vars(get_defined_vars());
  list_vars(get_defined_vars(),'t_');
*/function list_vars($a_vars,$pmatch = null) {
  print "'defined' Vars:";
 foreach ($a_vars as $key => $value) {
if (isset($pmatch)) {
   if (substr($key,0,strlen($pmatch)) == $pmatch) {
  print "$key = $value";
   }
} else {
   print "$key = $value";
}
 }
}


Cheers,
Donovan


P.S. Always open to good criticism if you peeps see something that can 
be written better.. this is about my 3rd PHP project only... so, still 
heavily learning ;-)



--
D Brooke

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