SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 28
  1. #1
    SitePoint Addict lundberg's Avatar
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Are you following PEAR standard?

    Hi,

    I was just woundering if you (when coding php) follows the PEAR standard?

    PEAR website: http://pear.php.net/

    Martin Lundberg
    Sweden

  2. #2
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I write my own standards ;P

    Besides, PEAR is far from *decent*

    Pick a style, and stick with it
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  3. #3
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no , tried to, but can't
    Regardless of the state of PEAR , coding standards sound like a good idea but its sooo subjective.

  4. #4
    SitePoint Addict lundberg's Avatar
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it's a good idea, im going to try it out, will tell you later how it went =P

    Martin Lundberg
    Sweden

  5. #5
    SitePoint Evangelist worksdev's Avatar
    Join Date
    Mar 2002
    Location
    Central, PA - originally from Monterey, CA
    Posts
    497
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello All:

    I was just researching PHP coding standards the other day to develop my own.

    The most thorough example document I found was:
    http://utvikler.start.no/code/php_coding_standard.html

    I took a look at PEARs coding standards. I didn’t love them, but that’s okay, the point is (as you have already mentioned) to find a standard you like and stick with it.

    I am using the sources I have looked and tweaking a bit.

    I also looked at this project’s coding standards, but have not read through it yet:
    http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=261&cHash=84f8279285

    And
    PHPBB’s Coding Standards (a great example of short standards)
    http://phpbb.sourceforge.net/docs/guide-standards.html

    Best Regards,
    worksdev
    Church Website Design by Enlighten Web Services -
    Web design-hosting-support for Christian ministries
    Friendly Community of Webmasters
    Christian Websites :: Christian Web Design

  6. #6
    What a twist! Kings's Avatar
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    954
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by worksdev
    And
    PHPBB’s Coding Standards (a great example of short standards)
    http://phpbb.sourceforge.net/docs/guide-standards.html
    Those seem to be pretty simple and straight-forward. I might actually start using them
    Dennis Pallett - NoCertainty - My Personal Weblog
    The Web Network: ASPit | PHPit | WebDev-Articles
    Blogs: TalkFones | Holidayzer | PHPit Blog

  7. #7
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    More or less, with some variations of my own.....

    I'm not fanatical about it though.

  8. #8
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty close to the phpBB standards, there are always exceptions though, like their spaces for everything, I don't feel the need to do this:
    PHP Code:
    for ($i 0$i 10$i++) 
    When this is just as readable IMO:
    PHP Code:
    for ($i=0$i 10$i++) 
    Again, sometimes I think there should be a space there for readability, sometimes not.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  9. #9
    SitePoint Evangelist worksdev's Avatar
    Join Date
    Mar 2002
    Location
    Central, PA - originally from Monterey, CA
    Posts
    497
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by worksdev

    The most thorough example document I found was:
    http://utvikler.start.no/code/php_coding_standard.html
    What I like about the standard I listed here is that it goes into standards for Classes and how they might differ from functions and regular coding standards.
    Church Website Design by Enlighten Web Services -
    Web design-hosting-support for Christian ministries
    Friendly Community of Webmasters
    Christian Websites :: Christian Web Design

  10. #10
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    for phpbb standards, I dont like this:

    $current_user is right, but $currentuser and $currentUser are not.

    I'd prefer use the second word first letter uppercased (3rd one) than using the first one.

  11. #11
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i follow the rsdl-standard.

    i don't follow ANY standard really , it's all good as long as it works and of course as long as it's readable to me.

    i agree with astericks on his comment, though i didn't start doing that till recently in my projects

    -rsdl

  12. #12
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no way. i think PEAR sucks.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  13. #13
    SitePoint Evangelist worksdev's Avatar
    Join Date
    Mar 2002
    Location
    Central, PA - originally from Monterey, CA
    Posts
    497
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DR_LaRRY_PEpPeR
    no way. i think PEAR sucks.
    DR_LaRRY_PepPeR:

    What do you think of the standards discussed in the other link I posted above? I’d really like your opinion because I am seriously looking at this issue to try and develop a set of my own “best practices” to use on projects.

    Thanks:
    Sean
    Church Website Design by Enlighten Web Services -
    Web design-hosting-support for Christian ministries
    Friendly Community of Webmasters
    Christian Websites :: Christian Web Design

  14. #14
    SitePoint Enthusiast petersj's Avatar
    Join Date
    Aug 2002
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont like:

    PHP Code:
    if (condition
    {
       
    do_stuff();

    I find this easier to read:

    PHP Code:
    if (condition) {
       
    do_stuff();


  15. #15
    SitePoint Addict lundberg's Avatar
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmmm, im confused now!
    I'll just do my own =P

    peetersj: your code didn't show =)

    Martin Lundberg
    Sweden

  16. #16
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ummm.... PEAR standards ? Never used it before and I sure don't want to either. Here is how I do things:

    PHP Code:
    .
    .
    .
    # this will do nothing
    if($cat == (string) 'feline') {
    # we have a cat here
    .
    .
    .
    }
    ,
    ,
    ,
    /**
     * another example of some comments
     */
    else {
    # we do not have a cat.. could be a dog ?
    }
    .
    .


  17. #17
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by worksdev
    DR_LaRRY_PepPeR:

    What do you think of the standards discussed in the other link I posted above? I’d really like your opinion because I am seriously looking at this issue to try and develop a set of my own “best practices” to use on projects.
    i didn't look at the link, sorry. it's pretty long. i'll check it out when i have more time to read it all.

  18. #18
    SitePoint Addict lundberg's Avatar
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well the most important thing is that you follow your own standard and don't write different code in your projects.

    Martin Lundberg
    Sweden

  19. #19
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Following your own standards is fine if the scripts you write are mostly for yourself; though if your working within a team/group then an agreed standard helps a lot. 8)

  20. #20
    SitePoint Addict lundberg's Avatar
    Join Date
    Mar 2003
    Location
    Sweden
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well yes, you have to adapt to the situation =)

    Martin Lundberg
    Sweden

  21. #21
    SitePoint Addict
    Join Date
    Feb 2001
    Posts
    302
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by petersj
    I dont like:

    PHP Code:
    if (condition
    {
       
    do_stuff();

    I find this easier to read:

    PHP Code:
    if (condition) {
       
    do_stuff();

    I am the total opposite, I much prefer the first way, with the curly brackets on their own line, that way when you are nesting 'ifs' it is easy to find the top and bottom bracket as they vertically parallel to each other.

  22. #22
    SitePoint Guru
    Join Date
    Feb 2002
    Posts
    625
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by neil100
    I am the total opposite, I much prefer the first way, with the curly brackets on their own line, that way when you are nesting 'ifs' it is easy to find the top and bottom bracket as they vertically parallel to each other.
    Personally, i prefer the curly brackets to be on there own line as well.
    Though this is really something that differs from developer to developer.

    You don't really need the PHP coding standard to write clean, readable and consistent code.

    If you prefer
    PHP Code:
    function foo {
        
    //do something
        

    than that's fine. As long as you stick with this convention throughout the rest of your code. Many times have i seen people not do this.

    Another really important thing is naming conventions. This is also something which could be argued over all day long.

    To me the most important thing is being consistent.
    I hate it if people start using variable names like this
    PHP Code:
    $allowed_ips 
    And if you look 3 lines further you see something like
    PHP Code:
    $dbUser 
    and again three lines later you see

    PHP Code:
    $dbconfig 
    That's what i would call sloppy code.

    Another thing i dislike which really a lot of people do is writing a 250 col. long SQL statement (for example)
    PHP Code:
    $sql "INSERT INTO table (foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar, foo, bar) VALUES ('$foo', '$bar', '$foo', '$bar', '$foo', '$bar', '$foo', '$bar', '$foo', '$bar', '$foo', '$bar', '$foo', '$bar', '$foo', '$bar') WHERE this='that' AND table.this=table.that"
    IMHO you should try not to exceed 80 col. and write your SQL statements in a more readable form. As in:
    PHP Code:
    $sql "INSERT INTO table " 
            
    "(bla, bla, bla, bla, bla, bla, bla, bla, bla, bla, bla, bla, bla, bla, bla) "
            
    "VALUES (
                             '
    $bla', '$bla', '$bla', '$bla', $bla', '$bla', '$bla', '$bla', 
                             '
    $bla', '$bla', '$bla', '$bla'
                           ) "
            
    "WHERE this='that' "
            
    "AND table.this=table.that"
    Another thing which really helps making code more readable (IMHO) is the following:

    PHP Code:
    $this->currentPage $currentPage;
    $this->pageCount   $pageCount;
    $this->page        =& $page;
    $this->smarty      =& $smarty;
    $this->db          =& $db
    instead of
    PHP Code:
    $this->currentPage=$currentPage;
    $this->pageCount=$pageCount;
    $this->page=&$page;
    $this->smarty=&$smarty;
    $this->db=&$db
    This can even be applied when building up arrays
    PHP Code:
            $this->entries[] = array (
                                    
    'id'      => $row['id'], 
                                    
    'name'    => $row['name'], 
                                    
    'email'   => $row['email'],
                                    
    'website' => make_clickable($row['website']),
                                    
    'date'    => formatDateTime($row['date'],0), 
                                    
    'time'    => formatDateTime($row['date'],1),
                                    
    'message' => $message
                                 
    ); 
    I think all of the above mentioned helps keeping your code clean and readable.

    As for the rest, i don't think we need a strict PHP coding guideline. Common sense will tell you if your code is written clean and readable. (Of course, when working in groups, you define a coding guideline which is valid for the project, but that's something different).

    Anyway, hope this helps someone out there

  23. #23
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [WARNING: RANT ALERT]

    Think far more important than standards relating to PHP syntax is standards in terms of design.

    In all software projects eventually something will change or someone else wants to use your code and either you or they will have to re-write some of it. How much re-writing depends on the design and IMO, as long as the design is good, who cares about the syntax?

    I know classes aren't what everyone is hot on but in my opinion, unless the PHP community wakes up to object oriented design practices, five years from now PHP will be a dead parrot.

    That may seem like an extreme statement but I think it's one of the main reasons why PHP5 is on the way - solid OOP.

    The "problem" is best explained by example.

    Ask yourself how easy is it to integrate phpBB (a great project but 90% procedural code) with your existing user authentication system? Unless you either re-write either your entire site or phpBB, you'll force your sites visitors to have two logins to your site, a seperate one for the forum.

    Over at hotscripts you'll find a ton of free PHP code; a massive amount of work by the PHP community. Unfortunately most of it can only do exactly what it was designed for. The moment you try customizing it or integrating it with other applications, you're talking massive re-writes (you may as well re-write the whole thing from scratch in most cases). Why is it every week someone realeases yet another CMS on Hotscripts? Because they couldn't use the rest?

    The "competition", in the form of ASP.NET and Java/JSP is (very) slowly catching up. The reason is they practically enforce development of truly reusable / integratable code; that means eventually, once they have a library of code out there the size of PHP's, putting together a site with one of those technologies and making future changes will take only a fraction of the time it takes with PHP.

    Once PHP5 happens, we're in with a chance to make PHP unquestionably the master of the web. But if the majority of PHP code continues to be procedural...

    As to PEAR, I know it takes alot of flak but the idea behind it is good and it has delivered some successful projects, such as PEAR::SOAP, which is excellent IMO. If they went further to introduce design standards, PEAR could benefit significantly (perhaps this will happen with PHP5).

    If you're looking to get started with OOP, it's worth learning first how to use classes written by other people. A good one to start with, IMO, is phpmailer which adds a whole load of functionality to the mail() function (attachments, HTML mail etc).

    The important thing to get from it is how to read API documentation (in this case just a single page), then compare it to the examples provided until it makes sense. Good projects should provide API docs (they're usually generated automatically from the comments in the code). It will then get easier to read API docs like those for Eclipse, which deal with multiple classes.

    Also check out Kevin's Object Oriented PHP: Paging Result Sets which will introduce you the OO syntax nicely.

    If you're interested, there's more here in Guidelines for Designing Classes in PHP, which is a collection of "good practices" that I've picked up along the way (many from discussions on these forums) and things that I see going wrong with much of the open source code out there. That's my contribution to coding standards.

    Anyway, excuse the rant / lecture . I'm not trying to say this from some arrogant point of view - I've written a ton of procedural code in PHP in the past which I now suffer from having to maintain (and I'm losing hair as a result!).

    There's is a value in procedural code when experimenting / prototyping code but these days I've always got my mind on a class to solve the problem and I never put that type of code into a "live" environment any more.

    In general I think OOP is made into a big deal when in fact, once you get into it, it's very simple (it's more like the way your brain works). If people got taught OOP from the start, I think they'd think that procedural code is too hard.

    [/RANT]

  24. #24
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personally I'm not a big fan of PEAR full stop, it's for from ideal or efficient in the most part. One of the most ludicrus (sp?) things abotu the PEAR coding standard is that you must use 4 spaces on indenting? What's wrong with a one tab? Then people can set their own preferance for the size of tabs, I know I prefer a tab size of 6 spaces, it makes it easier to spot code blocks when quickly scanning through code, so saying people must have 4 spaces is just plain stupid IMHO.

    My own style looks something like the following:
    PHP Code:
    <?php
     
    class someClass
     
    {
      var 
    $someData 'My Data';
      function 
    someClass$someArg$someOtherArg )
      {
       
    $this->someData $someArg $someOtherArg;
      }
      function 
    someFunction$anArgument )
      {
       return 
    $anArgument;
      }
     }
     
    $myClass = new someClass'My''Data' );
     if( 
    $myClass->someFunction'test' ) == 'test' ) {
      echo 
    'It Worked';
     } else {
      echo 
    'It Didn\'t Work';
     }
     for( 
    $loop 1$loop <=10$loop++ ) {
      echo 
    $loop'<br />';
     }
    ?>
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  25. #25
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems vB took a dislike to my blank lines, it was all nicely clearly spaced.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.


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
  •