PHP: Basics

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    PHP: Basics

    This will serve as the layout of the article. If anyone can chime in and tell me what I've missed, what is incorrect, etc., that'd be much appreciated.

    (unfinished)
    1. Prerequisites
    2. Abstract
    3. What Is This Article?
    4. Brief Description of PHP
      • The different PHP versions
      • When is PHP useful
      • When is it not
      • Why PHP rules
    5. Variables
      • Naming guidelines / conventions
      • Variable scope
      • Variable types
    6. Constants
    7. Operators
      • Brief overview of the most commonly used operators: ==, +=, etc., - I can refer visitors to the manual for a complete reference.
    8. Conditional Statements (if, elseif, else, etc)
      • When to use switch() and when to use if, elseif, else.
    9. Loops
    10. Functions
      • Naming guidelines / conventions
      • Parameters / arguments / Passing by reference
      • Syntax (no curly braces / curly braces)
    11. Coding Conventions / Best Practices
      • What should be avoided
        • Register Globals
        • HTTP_* functions
        • Magic Quotes
    12. Further Reading
      • PHP.net
      • PHP: Intermediate
      • PHP: Advanced


    Of course Intermediate and Advanced have yet to be written ;)

    ----

    PHP: The Basics

    Prerequisites
    The only thing that is needed for this article to go smoothly for yourself is a working copy of the latest (stable) release for PHP - at the time of writing, the latest stable release is 5.2.10. As far as programming know-how is concerned, you are not expected to have any. That's not to say if you do have any programming experience in PHP or any other language, this article is not for you: if you're just looking to affirm something you may have learned some time ago, this article could be for you also.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    maybe it's a good idea to talk a bit about "good coding practice" (or something like that) say, "globals are evil" and the like and maybe some basic php.ini tweaks (like disable register_global s or magic_quotes_gp c)

    I guess you save up the objects for PHP: Advanced? (you could mention these and refer to a later article)

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      maybe it's a good idea to talk a bit about "good coding practice" (or something like that) say, "globals are evil" and the like and maybe some basic php.ini tweaks (like disable register_global s or magic_quotes_gp c)
      Good point. Added.

      I guess you save up the objects for PHP: Advanced? (you could mention these and refer to a later article)
      Yeah, just keeping things less frightening for newbies. I remember when I started out, OOP would make me run a mile.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Anything you think should be added Dorm, do let me know of. That goes for you too, Atli, if you're reading ;)

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          what about: "how to look up a function in the manual" or even "how to read the manual" ? sometimes I think people don't know the obvious.

          I don't know if it should be put in the basic article, but what I think is the greatest obstacle in using PHP is that you don't know (as newbie), what actually is possible to do, so maybe a "functional ity overview" (without explaining how it works) could be a good idea.

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by Dormilich
            what about: "how to look up a function in the manual" or even "how to read the manual" ? sometimes I think people don't know the obvious.
            Haha. A little section on RTFM, maybe?

            I don't know if it should be put in the basic article, but what I think is the greatest obstacle in using PHP is that you don't know (as newbie), what actually is possible to do, so maybe a "functional ity overview" (without explaining how it works) could be a good idea.
            So you mean like possible uses of PHP? Like examples of what it is good at?

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              Originally posted by Markus
              Haha. A little section on RTFM, maybe?
              only slightly more polite. some people seem not to know, that there is a manual at all. ;)

              Originally posted by Markus
              So you mean like possible uses of PHP? Like examples of what it is good at?
              for instance… examples are always good for explanation.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                regarding point 11. Coding standards

                is it practical to talk about writing style, like intendation, brace style (K&R, Allman, GNU, …), documentation/comments?

                the base point here would be maintenance.

                btw. switch() and if/elseif/else don't belong to "9. Loops" (that would be for/foreach/while/do…while)

                and another thing to the Prerequisite. PHP doesn't work without a program using it. this could be the CLI, but I doubt, most beginners will use that. you should mention that a server (e.g. Apache) or an IDE that supports PHP execution is required.

                I know that SubEthaEdit (Mac) can run PHP code without server.

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Originally posted by Dormilich
                  regarding point 11. Coding standards

                  is it practical to talk about writing style, like intendation, brace style (K&R, Allman, GNU, …), documentation/comments?

                  the base point here would be maintenance.
                  Not sure what you mean. Perhaps 'coding standards' is a little ambiguous. Maybe 'coding conventions' would be better? In this section I would talk about naming conventions (camel-case, etc), formatting, documentation (comments), amongst other things I cannot think of right now :D

                  btw. switch() and if/elseif/else don't belong to "9. Loops" (that would be for/foreach/while/do…while)
                  My bad - that should be under the 'Conditional Statements' section.

                  and another thing to the Prerequisite. PHP doesn't work without a program using it. this could be the CLI, but I doubt, most beginners will use that. you should mention that a server (e.g. Apache) or an IDE that supports PHP execution is required.

                  I know that SubEthaEdit (Mac) can run PHP code without server.
                  This is debatable - while Apache isn't necessary, I see your point that most people will be intending to use PHP as a web language. However, I wouldn't want to article to drift into setting up apache, etc. Instead, under the 'Further reading' section, I'll provide resources for setting up a webserver, and then in the 'Prerequisites' section, refer users to it.

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    Originally posted by Markus
                    Not sure what you mean. Perhaps 'coding standards' is a little ambiguous. Maybe 'coding conventions' would be better? In this section I would talk about naming conventions (camel-case, etc), formatting, documentation (comments), amongst other things I cannot think of right now :D
                    coding conventions is better, yes.
                    about brace style, I probably used the wrong words, should be rather indent style


                    Originally posted by Markus
                    However, I wouldn't want to article to drift into setting up apache, etc. Instead, under the 'Further reading' section, I'll provide resources for setting up a webserver, and then in the 'Prerequisites' section, refer users to it.
                    I didn't want a "setting up a webserver" section (I'm fine with giving the resources), but if you only install PHP and nothing else, some people might think it doesn't work because they can't see any output.

                    Comment

                    • Markus
                      Recognized Expert Expert
                      • Jun 2007
                      • 6092

                      #11
                      Originally posted by Dormilich
                      coding conventions is better, yes.
                      about brace style, I probably used the wrong words, should be rather indent style
                      OK, Dorm. :)

                      I didn't want a "setting up a webserver" section (I'm fine with giving the resources), but if you only install PHP and nothing else, some people might think it doesn't work because they can't see any output.
                      Understood, although the CLI does provide output. I'll go over the different options in the article.

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        Originally posted by Markus
                        although the CLI does provide output.
                        not very probable that a beginner would use the command line (esp. when using Windows)

                        Comment

                        • Dormilich
                          Recognized Expert Expert
                          • Aug 2008
                          • 8694

                          #13
                          programming style should be useful for setion 11 as well.

                          Comment

                          Working...