SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 30
  1. #1
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP has too many functions in the core?

    PHP has too many functions in the core

    Forgive me if this is old. I found it interesting, although its certainly not news in this forum. The other day I had to decide between using the words chaotic or haphazard to explain PHPs library design. I chose haphazard.

  2. #2
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Selkirk,

    Here's my 2 cents. I was originally a PHP programmer, and moved onto C (still love PHP though). I loved PHP's easy accsesibility to all functions I needed. For C, it took me at least 5 hours of looking and screwing around to get a simple regex to work. This is because of my compiler (Borland, not MSVC++). I had to fix the library for the compiler, import it, get the header file, then read the cryptic manual files. With PHP, when I wanted to do a regular expression, I just typed http://php.net/regex or something and within 10 minutes I was using it. Same with MySQL, C has to import libraries.

    The thing with PHP is -- everything's easily accesible. I don't see what's the harm. It's quick, it's functional, and it's straight forward. Have you tried C or C++?

    Again, just my 2 cents.

    Regards,
    Someonewhois

  3. #3
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,650
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    A puny 3000 methods? Try 10,000+ objects in the .NET framework (thank god for intellisense).

    I actually like the way php is structured. I can go OO when I need it, but I dont have to jump through hoops to have, or access, global functions.

    I would also add that alot of those php functions are synonyms, left in for backwards compatibility. I do grant that it is a bit chaotic, but that is the nature of the OSS beast, no?

    WWB

  4. #4
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    philosophy,religion innit

    3079 functions (which may have risen) is misleading , thats all functions , eg including many extension functions that are rarely used on a day to day basis.

    eg a base php installation will not have all of those functions immediatlely available. ... when did you last use udm_load_ispell_data() ? (a well named if mostly ignored function)

    There are a lot of duplicate functions & aliases which could be confusing but thats a case of backwards compatability and an ongoing effort to get the naming converntion right.

    the author notes that PERL only needs 'sort' as oppsed to ' sort, arsort, asort, krsort, ksort, natsort, natcasesort, rsort, usort,
    array_multisort, uasort, uksort, dbx_sort, imap_sort, ldap_sort, yaz_sort'


    well ignoring the last 4 as they are extension specific ... well I probably use 4 of those on a regular basis , but the knowledge that say ksort or krsort exist are useful from time to time ... would the author rather I used array_flip() and array_reverse() instead ? .. or do they need to go as well ?

    regardless the author should sleep well in knowing that at least sort() exists should they ever make the move , or perhaps as someonewhois alludes they should write thier own stack with pop and push to get the function count down a bit ?

    I bet there are about 100 functions most of us use on a day to day basis and as long as they do not add any bloat to the source I am happy to see more.

    My personal gripe is the order of function arguments especially with needle/haystack type args eg in_array() && strstr() etc where I often have to check the manual to see which goes where.

    Yes PERL has some funky shorthand (we just have '=' and ternary ?: but see how many of those you need to throw together to do an array_merge_recursive() and you may get the point.

  5. #5
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    That link is complete junk . I am a regular Perl user and know from bitter experience that having several mini languages and ten ways to do everything leads to messy, bug ridden, impossible to maintain code.

    It is also misleading on several counts. A large number of those functions are database ones, which as has already been pointed out are modules, and are not included in the Perl comparison. The PHP core language is very much smaller than Perl and mostly context free. It is easy to have fewer keywords when every one has umpteen flags and works differently depending on whether it is feeding (not fed) a list.

    PHP has far simpler object handling. Perl is much more flexible here, but only because the innards of Perl are exposed. And Perl has ties which further blur the distinction and everybody's code.

    Given that it doesn't have a class library, 3000 functions is pretty small. Now the gripes...

    The PHP names are inconsistent, have random underscores and are often completely wrong. What does call_user_func_array() mean for goodness sake? Thank god for the new reflection API.

    The merging of arrays and hashes into the same thing has made a dreadful mess of the array handling functions. I would also like to see PHP6 add square bracket overloading for objects and also make a better job of foreach() overloading.

    The core language should be documented separately from the extensions. That way the core language could be considered frozen, whilst the function libraries can be cleaned up.

    Some of the incoming stuff, such as the "final" keyword, is just silly.

    Perl has CPAN, Python has a class library, PHP has a poor compromise.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  6. #6
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Is it really possible to have too many functions in a language? I mean, the more the merrier...

  7. #7
    Super Ninja Monkey Travis's Avatar
    Join Date
    Dec 2001
    Location
    Sioux City, Iowa
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    More functions are fine, if they are really needed. However, I really like the way Python does it with their modules. Sometimes it might be harder to figure out what module has what, but the docs are great for that. It also means I can distribute a working Python script (interpreter and all) with only the stuff I need so its a much smaller app compared to bundling a PHP script with the interpreter and getting a 10MB file. I can get a 2MB file if all I really use is the base stuff and MySQL.
    Travis Watkins - Hyperactive Coder
    My Blog: Realist Anew
    Projects: Alacarte - Gnome Menu Editor

  8. #8
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Travis
    More functions are fine, if they are really needed. However, I really like the way Python does it with their modules. Sometimes it might be harder to figure out what module has what, but the docs are great for that. It also means I can distribute a working Python script (interpreter and all) with only the stuff I need so its a much smaller app compared to bundling a PHP script with the interpreter and getting a 10MB file. I can get a 2MB file if all I really use is the base stuff and MySQL.
    Very good point. The Python model is a very good one and I think that van Rossum's idea behind the whole language was ease of use, expandability, and small learning curve.

    Maybe if PHP adopted a similar model we would see large applications drop in size considerably?

  9. #9
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    Michigan, USA
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was one of my bigger gripes one I first started working with PHP more. Some of the functions are completely ludicris in my mind. nl2br()?? Come on, let's be serious. There are a lot of little functions that I laugh about when I come across them, but I guess I have no real complaints. I don't have enough knowledge of the innards of either language to say whether the amount of functions has anything that strikes against performance or other such things.

    Basically, the article looks to be completely unfounded and though I did get a good laugh out of seeing some of the mentioned PHP functions it's just a bunch of rubbish

    Oh, and CPAN is my hero!

  10. #10
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    vancouver
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    The PHP names are inconsistent, have random underscores and are often completely wrong. What does call_user_func_array() mean for goodness sake? Thank god for the new reflection API.
    What exactly is the Reflection API? I've seen mention of it several times, but haven't found any concrete description of what it is/does. Anyone have any good links explaining it?

  11. #11
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  12. #12
    SitePoint Zealot rae's Avatar
    Join Date
    Apr 2003
    Location
    bedroom :P
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Unknown_Relic
    What exactly is the Reflection API? I've seen mention of it several times, but haven't found any concrete description of what it is/does. Anyone have any good links explaining it?
    I don't know, but it's name is inconsistent!!! LOL
    PHP5 comes with a complete reflection API that adds the ability to reverse-engineer classes, interfaces, functions and methods as well as extensions
    Then why don't name that reverse engineer API??
    Anyway... I've read that stuff... it's interesting.

    Oh... and to stay at the topic... Have a look at c++ ! You won't say php has too much functions
    d(o.O)b -- Notice: undefined variable: /me

  13. #13
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some of the functions are completely ludicris in my mind. nl2br()?? Come on, let's be serious.
    seriously :: I use it serveral times a day , its a logical shortcut for a language originally developed for creating HTML should I str_replace instead ? the overhead in the source is minimal.

    I am also glad to see that str_ireplace() is coming with PHP5 , its usefulness could be argued away by looking at existing options but its a function I have been waiting for for a while now , faster than preg* , ereg* but matching arrays of needles in a case insensitve fashion ... gimme more !

  14. #14
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Andy Tomaka
    That was one of my bigger gripes one I first started working with PHP more. Some of the functions are completely ludicris in my mind. nl2br()?? Come on, let's be serious. There are a lot of little functions that I laugh about when I come across them, but I guess I have no real complaints. I don't have enough knowledge of the innards of either language to say whether the amount of functions has anything that strikes against performance or other such things.

    Basically, the article looks to be completely unfounded and though I did get a good laugh out of seeing some of the mentioned PHP functions it's just a bunch of rubbish

    Oh, and CPAN is my hero!
    Why do you laugh at nl2br() ??

  15. #15
    SitePoint Evangelist
    Join Date
    Jul 2001
    Location
    Michigan, USA
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Hartmann
    Why do you laugh at nl2br() ??
    Mainly because it can be handled by a solution that is only slightly longer. Yeah, some things that take multiple lines of coding in other scripting languages that have been shortened to a function in PHP are great, but if it only takes one short line, is it really worthwhile to add yet another function to the list? Like I said, I don't really have any huge beef with it; I am just slightly amused by it

  16. #16
    SitePoint Wizard Mike Borozdin's Avatar
    Join Date
    Oct 2002
    Location
    Edinburgh, UK
    Posts
    1,743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But nl2br () must be faster than str_replace () because PHP has to parse three parameters and some actions of str_replace () while nl2br () gets only one parameter and do the only action.

  17. #17
    Super Ninja Monkey Travis's Avatar
    Join Date
    Dec 2001
    Location
    Sioux City, Iowa
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nl2br() would be faster because it handles the conversion in C. With str_replace() you would be doing it in PHP. The difference probably wouldn't be all that significant, but for people like me who always want to make the fastest script possible, it makes a difference.
    Travis Watkins - Hyperactive Coder
    My Blog: Realist Anew
    Projects: Alacarte - Gnome Menu Editor

  18. #18
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP is written in C , it does not do anything in C , str_replace and nl2br are both handled by the interpreter , it follows that nl2br() should faster as Mike says it has less parameters to mung , but whatever the speed difference its a great little function , the sort of thing that makes our lives that little more pleasant

  19. #19
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    The trouble is almost any PHP function can be described as useful. On their own they probably are, it's just that together they add clutter. That clutter is a load for the PHP developers as much as it is for us. Some of them get broken occasionally (e.g. parse_url() in 4.3.0).

    To justify a function here are some criteria off the top of my head...
    1) Easy and obvious to use, especially to a beginner.
    2) Useful to the broad user base.
    3) Powerful, but not by way of just adding lot's of options.

    Number one is more specific to PHP. nl2br() scores well on 1, but scores near zero on the others. The correct question is not whether you find a function useful, but if you had to deprecate some, which ones would go.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  20. #20
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP doesn't really have too many function - it just annoying that they are not in a proper class library. Since PHP doesn't have namespaces at all, or any other way to separate code naming, there is a tendency to accidentally name one of your own functions the same as one of the 3000 inbuilt ones. I did it several times when I was doing PHP. Some of the functions is REALLY generically named and really easy to "hit" by accident, such as gettext(), for instance.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  21. #21
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by M. Johansson
    PHP doesn't really have too many function - it just annoying that they are not in a proper class library. Since PHP doesn't have namespaces at all, or any other way to separate code naming, there is a tendency to accidentally name one of your own functions the same as one of the 3000 inbuilt ones. I did it several times when I was doing PHP. Some of the functions is REALLY generically named and really easy to "hit" by accident, such as gettext(), for instance.
    That's true. But that's really more of a lack-of-namespaces issue than anything else.

    This is actually one of the things that Perl does a lot better than PHP. Perl gives you so much control over variable scope and the symbol table.

    Are namespaces still being left out of PHP5?

    BTW, is that article that selkirk posted gone? I got a "not found" message or something?

    --ed

  22. #22
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Watford, UK
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by coo_t2
    BTW, is that article that selkirk posted gone? I got a "not found" message or something?
    Yeah, it'd gone by the time i got to it. I like the idea of the scribbler app.

    Cheers,

    Jon

  23. #23
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I get a "Scribblet cannot be found message".
    Wayne Luke
    ------------


  24. #24
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heres a little cleaner version...
    http://ajohnstone.com/obj_php5.php

  25. #25
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the Google cache for that page as someone "unscribbled" the original.

    There's a simple question to answer that specific Perl vs PHP comparison. How long does it take to learn Perl's syntax? And how long PHP?

    To quote Bruce Eckel...

    I have come, however, to always be on watch for a Faustian bargain, especially one that tries to convince me to ignore all the hoops I must jump through in order to achieve this abstraction. Perl is an excellent example of this the immediacy of the language hides the meaningless details of building a program, but the unreadable syntax (based, I know, on backwards-compatibility with Unix tools like awk, sed and grep) is a counterproductive price to pay.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •