how to suggest a new function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam  Scheinberg

    #1

    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

  • flamer die.spam@hotmail.com

    #2
    Re: how to suggest a new function?


    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.

    Comment

    • Benjamin

      #3
      Re: how to suggest a new function?


      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
      "personaliz ed" 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

      Comment

      • Adam  Scheinberg

        #4
        Re: how to suggest a new function?


        On Dec 3, 10:38 pm, "Benjamin" <musiccomposit. ..@gmail.comwro te:
        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
        "personaliz ed" 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 "personaliz ed?" 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.

        Comment

        • Michael Fesser

          #5
          Re: how to suggest a new function?

          ..oO(Adam Scheinberg)
          >On Dec 3, 10:38 pm, "Benjamin" <musiccomposit. ..@gmail.comwro te:
          >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
          >"personalize d" 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 "personaliz ed?" 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

          Comment

          • Adam  Scheinberg

            #6
            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_conten ts() can be accomplished with three existing functions -
            fopen(), fwrite(), and fclose(). All three are present in PHP 5.
            Same with file_get_conten ts 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.de wrote:
            .oO(Adam Scheinberg)
            >
            On Dec 3, 10:38 pm, "Benjamin" <musiccomposit. ..@gmail.comwro te:
            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
            "personaliz ed" 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 "personaliz ed?" 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

            Comment

            • Michael Fesser

              #7
              Re: how to suggest a new function?

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

              Comment

              • Benjamin

                #8
                Re: how to suggest a new function?


                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_conten ts() can be accomplished with three existing functions -
                fopen(), fwrite(), and fclose(). All three are present in PHP 5.
                Same with file_get_conten ts 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_conten ts(). 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.de wrote:
                .oO(Adam Scheinberg)
                >On Dec 3, 10:38 pm, "Benjamin" <musiccomposit. ..@gmail.comwro te:
                >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
                >"personalize d" 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 "personaliz ed?" 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

                Comment

                • Oliver Grätz

                  #9
                  Re: how to suggest a new function?

                  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_ge t_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

                  Comment

                  Working...