473,472 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Dec 4 '06 #1
8 1851

Adam Scheinberg wrote:
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.

Dec 4 '06 #2

Adam Scheinberg wrote:
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.
>
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
Dec 4 '06 #3

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.
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.

Dec 4 '06 #4
..oO(Adam Scheinberg)
>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.

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.
>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
Dec 4 '06 #5
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:
.oO(Adam Scheinberg)
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.
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.
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
Dec 4 '06 #6
..oO(Adam Scheinberg)
>print_r ALREADY returns a formatted array.
Correct, but it's plain text.
>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.
>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.
>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
Dec 4 '06 #7

Adam Scheinberg wrote:
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?
>
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.
>
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:
.oO(Adam Scheinberg)
>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.
>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.
>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
Dec 5 '06 #8
Adam Scheinberg schrieb:
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.
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.
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
Dec 5 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jean Paul Sartre | last post by:
can anyone suggest a function that will spit out the dom path for an object on id? I'm having troubles targettting elements so i thought, if i make a function that spits path (you send it id) then...
5
by: gimme_this_gimme_that | last post by:
I'd like to create my own version of google suggest GS. If you haven't seen GS check it out at : http://www.google.com/webhp?complete=1&hl=en I've reviewed several AJAX write-ups on the...
0
by: Waran | last post by:
I need to create a Auto suggests Textboox like in http://www.google.com/webhp?complete=1&hl=en I have completed this using AJAX.NET for Framework 1.1 . I have some design issues after the data is...
0
by: Waran | last post by:
Hi, Please look the fields (Insurance, Defense Attorney, Applicant/Plaintiff Attorney) under party list in http://www.reccustodian.com/defensepro/order/neworder.aspx The above said fields are...
2
by: awebguynow | last post by:
It seems like I've been reading the code to Google Suggest (GS) for about a week, and I'm going to have to wrap it up shortly. I'm OK with many of the subjects, and I would say I have...
2
by: Krypto | last post by:
Hi, I have learned some basic C++ but when it comes to applying the concepts of Inheritance, Virtual functions I feel as if I don;t know which project to apply these concepts to. I thought that...
16
by: Martin Wells | last post by:
I'm doing an embedded systems college project this year. I'm making a portable device that will take input in the form of simple switches, and give output in the form of LED's. Can you please...
0
by: Peter Duniho | last post by:
On Thu, 26 Jun 2008 00:05:42 -0700, <zorrothefox.groups@gmail.comwrote: Yes, it is "klunky". IMHO, it's unfortunate that that's the model MSDN continues to suggest everywhere. If you are...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.