how to suggest a new function? | | |
Hello all,
This is my first post and I'm wondering if someone can point me in the
right direction. I have seen the following code MANY times in programs
and throughout the internet:
<?php
echo '<pre>';
print_r($array);
echo '</pre>';
?>
As a result, I often create a function called print_r_pre() in my code
to mimic this during development, which is highly useful in
interpreting large arrays. It seems, though, that when using
print_r(), mostly people would *usually* want this behavior (and not
just in the source code).
I would like to suggest to develpers one of three things:
1. Most desirable: the introduction of a new function, print_r_pre()
which takes the same arguments as print_r().
2. Secondly: add a third argument to print_r(), which allows you to use
print_r($array,0,1) or somesuch.
or
3. The least desirable: change the default behavior of this function to
spit <pretags
My problem is, I'm not sure how to do this - do I do this on the
internals mailing list? The general php list?
Can anyone point me in the right direction?
A | | | | re: how to suggest a new function?
Adam Scheinberg wrote: Quote:
Hello all,
>
This is my first post and I'm wondering if someone can point me in the
right direction. I have seen the following code MANY times in programs
and throughout the internet:
>
<?php
echo '<pre>';
print_r($array);
echo '</pre>';
?>
>
As a result, I often create a function called print_r_pre() in my code
to mimic this during development, which is highly useful in
interpreting large arrays. It seems, though, that when using
print_r(), mostly people would *usually* want this behavior (and not
just in the source code).
>
I would like to suggest to develpers one of three things:
>
1. Most desirable: the introduction of a new function, print_r_pre()
which takes the same arguments as print_r().
2. Secondly: add a third argument to print_r(), which allows you to use
print_r($array,0,1) or somesuch.
or
3. The least desirable: change the default behavior of this function to
spit <pretags
>
My problem is, I'm not sure how to do this - do I do this on the
internals mailing list? The general php list?
>
Can anyone point me in the right direction?
>
A
php.net
Flamer. | | | | re: how to suggest a new function?
Adam Scheinberg wrote: Quote:
Hello all,
>
This is my first post and I'm wondering if someone can point me in the
right direction. I have seen the following code MANY times in programs
and throughout the internet:
>
<?php
echo '<pre>';
print_r($array);
echo '</pre>';
?>
>
As a result, I often create a function called print_r_pre() in my code
to mimic this during development, which is highly useful in
interpreting large arrays. It seems, though, that when using
print_r(), mostly people would *usually* want this behavior (and not
just in the source code).
>
I would like to suggest to develpers one of three things:
>
1. Most desirable: the introduction of a new function, print_r_pre()
which takes the same arguments as print_r().
2. Secondly: add a third argument to print_r(), which allows you to use
print_r($array,0,1) or somesuch.
or
3. The least desirable: change the default behavior of this function to
spit <pretags
This sort of function might be nice for you but things like this are
really what user functions are for. If PHP kept adding new
"personalized" functions to the source, PHP would become really bloated
and bulky. If you really want that function, you could create your own
extension in C. Quote:
>
My problem is, I'm not sure how to do this - do I do this on the
internals mailing list? The general php list?
>
Can anyone point me in the right direction?
>
A
| | | | re: how to suggest a new function?
On Dec 3, 10:38 pm, "Benjamin" <musiccomposit...@gmail.comwrote: Quote:
This sort of function might be nice for you but things like this are
really what user functions are for. If PHP kept adding new
"personalized" functions to the source, PHP would become really bloated
and bulky. If you really want that function, you could create your own
extension in C.
Why is this "personalized?" What I said was I see it all over the
place. Chaging the behavior of an existing function does not "add
bloat" if it does what develpers intended it to do. That's the cry of
someone who has read too much Slashdot. | | | | re: how to suggest a new function?
..oO(Adam Scheinberg) Quote:
>On Dec 3, 10:38 pm, "Benjamin" <musiccomposit...@gmail.comwrote: Quote:
>This sort of function might be nice for you but things like this are
>really what user functions are for. If PHP kept adding new
>"personalized" functions to the source, PHP would become really bloated
>and bulky. If you really want that function, you could create your own
>extension in C.
>
>Why is this "personalized?" What I said was I see it all over the
>place.
I don't, because such things should only be used while developing, not
in productive code. Additionally printing it out as preformatted HTML
might be the most common way, but not necessarily always the best.
You're better off with writing your own function that does exactly what
you want and need. Write it once, put it in an external file, include it
and you can use it all the time. In my applications for example I use
two of them:
debugPrint() -returns preformatted HTML
debugLog() -writes the output to a logfile
I would never expect PHP to already ship with such functions included. Quote:
>Chaging the behavior of an existing function does not "add
>bloat" if it does what develpers intended it to do.
Changing it the way you intended would be unnecessary bloat. Currently
print_r() returns raw data, which is perfectly fine for all kinds of
further processing. Changing it to already return a specific formatting
like HTML doesn't really make sense and would limit its uses (IMHO).
Micha | | | | re: how to suggest a new function?
print_r ALREADY returns a formatted array. If you snoop the source,
you'll see it yourself. It just doesn't return it with the <pretags
around it, which is TRIVIAL to add.
Furthermore, including such code in all development is slow - in each
successfive page load PHP will have to parse a function, rather than
having it precompiled in, which is loads faster.
file_put_contents() can be accomplished with three existing functions -
fopen(), fwrite(), and fclose(). All three are present in PHP 5.
Same with file_get_contents before 4.3. So these are bloat, right?
You see? It's never bloat if it adds beneficial utility. The arugment
that something like this would add "bloat" is probably from someone who
is unconvinceable to begin with, because they are coming to the table
with baggage.
I can't think of why echo'ing the contents of print_r() without
formating would *ever* be a requirement, but I guess this group has
spoken.
A
On Dec 4, 9:55 am, Michael Fesser <neti...@gmx.dewrote: Quote:
.oO(Adam Scheinberg)
> Quote:
On Dec 3, 10:38 pm, "Benjamin" <musiccomposit...@gmail.comwrote: Quote:
This sort of function might be nice for you but things like this are
really what user functions are for. If PHP kept adding new
"personalized" functions to the source, PHP would become really bloated
and bulky. If you really want that function, you could create your own
extension in C.
> Quote:
Why is this "personalized?" What I said was I see it all over the
place.I don't, because such things should only be used while developing, not
in productive code. Additionally printing it out as preformatted HTML
might be the most common way, but not necessarily always the best.
>
You're better off with writing your own function that does exactly what
you want and need. Write it once, put it in an external file, include it
and you can use it all the time. In my applications for example I use
two of them:
>
debugPrint() -returns preformatted HTML
debugLog() -writes the output to a logfile
>
I would never expect PHP to already ship with such functions included.
> Quote:
Chaging the behavior of an existing function does not "add
bloat" if it does what develpers intended it to do.Changing it the way you intended would be unnecessary bloat. Currently
print_r() returns raw data, which is perfectly fine for all kinds of
further processing. Changing it to already return a specific formatting
like HTML doesn't really make sense and would limit its uses (IMHO).
>
Micha
| | | | re: how to suggest a new function?
..oO(Adam Scheinberg) Quote:
>print_r ALREADY returns a formatted array.
Correct, but it's plain text. Quote:
>If you snoop the source,
>you'll see it yourself. It just doesn't return it with the <pretags
>around it, which is TRIVIAL to add.
But not always wanted or necessary. Quote:
>Furthermore, including such code in all development is slow - in each
>successfive page load PHP will have to parse a function, rather than
>having it precompiled in, which is loads faster.
Don't tell me you're worried about a single function being loaded each
time! Including a single file with some useful helper functions doesn't
make much of a difference, in fact you won't be able to measure it.
There are much "better" ways to waste CPU time. Quote:
>I can't think of why echo'ing the contents of print_r() without
>formating would *ever* be a requirement, [...]
Usually you don't want a HTML output, when you're
* using PHP-CLI
* writing the output to a logfile
* sending just plain text with header('Content-Type: text/plain')
Just some examples.
Changing the default behaviour of print_r() would definitely be the
wrong way. Of course you're free to suggest an additional function or a
third parameter to the PHP dev team, but I still consider it rather
pointless and too much effort.
Micha | | | | re: how to suggest a new function?
Adam Scheinberg wrote: Quote:
print_r ALREADY returns a formatted array. If you snoop the source,
you'll see it yourself. It just doesn't return it with the <pretags
around it, which is TRIVIAL to add.
>
Furthermore, including such code in all development is slow - in each
successfive page load PHP will have to parse a function, rather than
having it precompiled in, which is loads faster.
You must be afraid to write anything in PHP; merely adding "<pre>" and
"</pre>" is hardly worth a millisecond. Besides you only use this when
you're developing, right? Quote:
>
file_put_contents() can be accomplished with three existing functions -
fopen(), fwrite(), and fclose(). All three are present in PHP 5.
Same with file_get_contents before 4.3. So these are bloat, right?
You see? It's never bloat if it adds beneficial utility. The arugment
that something like this would add "bloat" is probably from someone who
is unconvinceable to begin with, because they are coming to the table
with baggage.
Those file functions are a different story. They can be used for
writing and reading to streams; that's something that can't be
accomplished with just file_put_contents(). The custom print_r()
function you speak of doesn't add much functionality. That's why we
have user functions. Quote:
>
I can't think of why echo'ing the contents of print_r() without
formating would *ever* be a requirement, but I guess this group has
spoken.
>
A
>
On Dec 4, 9:55 am, Michael Fesser <neti...@gmx.dewrote: Quote:
.oO(Adam Scheinberg) Quote:
>On Dec 3, 10:38 pm, "Benjamin" <musiccomposit...@gmail.comwrote:
>This sort of function might be nice for you but things like this are
>really what user functions are for. If PHP kept adding new
>"personalized" functions to the source, PHP would become really bloated
>and bulky. If you really want that function, you could create your own
>extension in C.
Quote:
>Why is this "personalized?" What I said was I see it all over the
>place.I don't, because such things should only be used while developing, not
in productive code. Additionally printing it out as preformatted HTML
might be the most common way, but not necessarily always the best.
You're better off with writing your own function that does exactly what
you want and need. Write it once, put it in an external file, include it
and you can use it all the time. In my applications for example I use
two of them:
debugPrint() -returns preformatted HTML
debugLog() -writes the output to a logfile
I would never expect PHP to already ship with such functions included. Quote:
>Chaging the behavior of an existing function does not "add
>bloat" if it does what develpers intended it to do.Changing it the way you intended would be unnecessary bloat. Currently
print_r() returns raw data, which is perfectly fine for all kinds of
further processing. Changing it to already return a specific formatting
like HTML doesn't really make sense and would limit its uses (IMHO).
Micha
| | | | re: how to suggest a new function?
Adam Scheinberg schrieb: Quote:
1. Most desirable: the introduction of a new function, print_r_pre()
which takes the same arguments as print_r().
Yep, and let's introduce var_dump_pre(), var_dump_pre_get_as_string(),
print_r_as_html_table(), print_r_xml()...
Nope, this doesn't make sense. print_r fulfills one function:
transforming a data structure into a string representation describing
the data structure. It does this and nothing more. Mixing it with
specialized formatting code does not add functionality, it takes away
flexibility.
For my part: Yes, I do use print_r() surrounded by <pretags. But even
more I use print_r() with its behaviour set to returning a string. Then
I let PHP write this string into a logfile! Outputting debug information
into the browser is a bad habit!! We all do it but it's wrong. And
encouraging bad habits by supplying more convenient functions to do it
is a bad idea. Quote:
2. Secondly: add a third argument to print_r(), which allows you to use
print_r($array,0,1) or somesuch.
This is even worse than number 1! First of all it is less
comprehensible, people would start looking "What was that 3rd parameter
for?" and then another parameter means checking for another parameter.
It takes away performance for all cases where the parameter is left in
its default state. Quote:
or
3. The least desirable: change the default behavior of this function to
spit <pretags
And breaking tons of existing applications! Sorry, but this is only an
option if you start compiling your own patched version of PHP. The devs
would tear and feather someone suggesting things like that.
In terms of better code it would be a good idea to change the default
behaviour of print_r() to returning a string so less people spill debug
info into the browser. But as I just explained...
OLLi |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|