SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Obsessive designer Infizi's Avatar
    Join Date
    May 2004
    Location
    North Pole
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP getting in over itself?

    Im starting to understand PHP5 finally, but i keep finding new functions that do the same thing as another function. Why have two methods?

    Issues have been discussd here time and time again about PHPs multi methods, but its some of the smaller things that i really dont understand,

    I mean, why have the array() function. ok, if you want to check if a variable is an array then yes, it is, but its got no data in it,

    why use

    $myarray = array("var" => "val", "again" => "var"),

    when you could just go

    $myarray['var'] = "val";
    $myarray['again'] = "var";

    really, try and create 3d, even 4d arrays using array() and your lost, try to edit one bit, no chance. its so much easier usiong $array['var']['3dvar'] = "cdval';!!!

    its not just this, theres millions of stupid things appearing that no one ever uses in reality, PHP is just getting so advanced its rewriting itself....

  2. #2
    SitePoint Guru gavwvin's Avatar
    Join Date
    Nov 2004
    Location
    Cornwall, UK
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are lots of things in php where they've brought in a function that does the job of several functions together in a common use, just to make things easier... like the glob function... you could opendir, readdir for each one and preg_match each file to find a certain type, but the glob function puts that all together in one, for our convenience.

  3. #3
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    plain $myarray['var'] = "val"; should generate a notice in case you haven't declared $myarray as an array (atleast if it's not introduced at all). Also, I really disagree with you. It can be a LOT easier to use array().
    You can do this:

    PHP Code:
    $variable["key"]["another_key"]["yet_another_key"] = array(
        
    "name" => "Mike",
        
    "id" => 1,
        
    "email" => "moo@example.com"
    ); 
    When using "your" method you'd have to do this:

    PHP Code:
    $variable["key"]["another_key"]["yet_another_key"]["name"] = "Mike";
    $variable["key"]["another_key"]["yet_another_key"]["id"] = 1;
    $variable["key"]["another_key"]["yet_another_key"]["email"] = "moo@example.com"
    And about multidimensional arrays: It's possible and not even hard. But yes, it is easier to write just $variable["key"]["another_key"]["yet_another_key"]["name"]. I can't disagree with that.

    The methods can also be combined.

    PHP Code:
    $a = array();
    $a["key"] = "value"
    I see nothing wrong with that piece of code.

    Quote Originally Posted by Infizi
    its not just this, theres millions of stupid things appearing that no one ever uses in reality, PHP is just getting so advanced its rewriting itself....
    Taking the short way usually generates notices, and one should never, I repeat, NEVER EVER ignore notices. It's ok if you develop just for yourself, but when it's about commercial/open source products.. It's a shame. It clearly shows that the developers have not been very careful when writing the code. I'd never buy a product that generates notices. Never. And register_globals... If I could, I'd take computers away from anyone using register_globals.

    Sorry if this post seems a bit aggressive but I just.. Oh well. I guess I made it quite clear.

  4. #4
    Obsessive designer Infizi's Avatar
    Join Date
    May 2004
    Location
    North Pole
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol,

    well thats the idea to provoke discussion.

    Its not just the array() function tho, theres quite a few others!!!

    And, just to let you know all my scripts are carefully designed before i even turn on my PC, best way to code, PLAN, REPLAN, INNOVATE, MAKE, INNOVATE, REWRITE

  5. #5
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    Finland
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh, I'm not blaming you because I've only seen like 4 lines of your code. I meant it all in a general way

  6. #6
    Obsessive designer Infizi's Avatar
    Join Date
    May 2004
    Location
    North Pole
    Posts
    450
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol, no probs.



    Quote Originally Posted by Sorccu
    Heh, I'm not blaming you because I've only seen like 4 lines of your code. I meant it all in a general way
    New Design - PHP Slowly flowing in!

    Infizi Studio's


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
  •