Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reading PHP Syntax

    Hey all,

    Does anybody know/have a book/online source/tutorial(free or otherwise) that teaches you how to read php? I mean the way you would literally say the code in english if you were to read it line by line.


    -R

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Code doesn't really have an english equivalent. It's all about variables really, comparing, setting, modifying etc.

    You're going to have to actually LEARN php if you want to understand it - the same applies to any language. You'll have head scratching moments but thats when you ask for help.

    I'm afraid there is no easy way to get the knowledge, you'll just have to learn and experiment with bits of code to see what they do etc.

    To help you along the way..
    tizag.com has good tutorials
    php.net has an excellent function reference manual with user contributed notes (very handy)
    google.com usually turns up bits of code you can use, study etc.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    With all due respect, I have to strongly disagree with you. Take the following code for example:

    PHP Code:
    if(isset($var)) {
    print 
    "This";
    } else {
    print 
    "That";

    it can be worded as: if the variable '$var' is set, or exists, print the statement "This", otherwise if it doesn't exists, print the statement "That". Also, if I saw the following function: float round ( float value [, int precision])
    I would read it as: the function named 'round' returns a float value, with its first parameter named 'value' being a float and its second(and optional) parameter named 'precision' being a interger.

    This is the approach I'm trying to get at, being able to say what the code does. Feedback? Suggestions?


    -R
    Last edited by username85; 10-24-2012 at 03:27 AM.

  • #4
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,269
    Thanks
    10
    Thanked 277 Times in 276 Posts
    I'm curious as to your need for this. I've never heard of this question before, and am honestly wondering what you're going to accomplish with it?

    Dave

  • #5
    New Coder
    Join Date
    Sep 2012
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm fairly sure most beginner guides to php would explain it like that.

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,327
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by username85 View Post
    With all due respect, I have to strongly disagree with you. Take the following code for example:

    PHP Code:
    if(isset($var)) {
    print 
    "This";
    } else {
    print 
    "That";

    it can be worded as: if the variable '$var' is set, or exists, print the statement "This", otherwise if it doesn't exists, print the statement "That". Also, if I saw the following function: float round ( float value [, int precision])
    I would read it as: the function named 'round' returns a float value, with its first parameter named 'value' being a float and its second(and optional) parameter named 'precision' being a interger.

    This is the approach I'm trying to get at, being able to say what the code does. Feedback? Suggestions?


    -R
    Fair enough.. but then why are you asking this question?

    BTW your description of round is also wrong - it should be: round takes a parameter that is a float with an optional second paraameter. It returns a value that is an integer. The way you've done it starts at the beginning, goes to the end and then comes back to the middle to explain the parameters.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #7
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by username85 View Post
    With all due respect, I have to strongly disagree with you. Take the following code for example:

    PHP Code:
    if(isset($var)) {
    print 
    "This";
    } else {
    print 
    "That";

    it can be worded as: if the variable '$var' is set, or exists, print the statement "This", otherwise if it doesn't exists, print the statement "That". Also, if I saw the following function: float round ( float value [, int precision])
    I would read it as: the function named 'round' returns a float value, with its first parameter named 'value' being a float and its second(and optional) parameter named 'precision' being a interger.

    This is the approach I'm trying to get at, being able to say what the code does. Feedback? Suggestions?


    -R
    It appears you're handling it pretty well. Are you sure you need a book?

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This is the wrong way around. You don't extract the algorithm (english or not) from the language, you manufacture the code to match the algorithm based on the language. Whilst you can manufacture the algorithm from the language, its much easier to go the other way around.
    Example in case:
    Code:
    set result as string value empty
    if var is 0 then
        set result as "nilslot"
    if var is 1 or 2 then
        set result as "clause1"
    else if var is 3 then
        set result as "clause2"
    else if (as char)var is '4' or 'v' then
        set result as "clause4"
    else if (as char)var is 't' then
        set result as "tslot"
    else
        set result as "other"
    Algorithmically that is fairly straight forward to read. But there is no need to use an if/else:
    Code:
    switch (k)
    {
        case 0:
            result = "nilslot";
            break;
        case 1:
        case 2:
            result = "clause1";
            break;
        case 3:
            result = "clause2";
            break;
        case '4':
        case 'v':
            result = "clause4";
            break;
        case 't':
            result = "tslot";
            break;
        default:
            result = "other"
    }
    
    // or in another language
    (case k ((1 2) 'clause1)
            (3 'clause2)
            (nil 'no-keys-so-never-seen)
            ((nil) 'nilslot)
            ((:four #\v) 'clause4)
            ((t) 'tslot)
            (otherwise 'other)))
    So as you can see writing a block of code from an algorithm is far easier done than extracting the algorithm from the code. I adapted the above using examples of the switch statement from here: http://c2.com/cgi/wiki?SwitchStatement; I don't use lisp (one day I'll learn it), but I was aware of the unusual structure of it compared to c based languages, so I thought it would be a good idea to get a switch example of the lisp.

    As mentioned though, you seem to read them fine. I doubt that a book would exist for interpreting a language to an algorithm, rather you will likely find books that describe how to write algorithms.


  •  

    Tags for this Thread

    Posting Permissions

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