Jump to content

General syntax question


KevinM1

Recommended Posts

I asked this in the miscellaneous category a while back and never got a response, so I figured I'd ask here as it seems like a better section in which to post this.

I have the Larry Ullman/Peachpit book (the one up to PHP4 and MySQL4).  I saw someone make a comment that the book uses the 'old' PHP syntax.  What is an example of the 'old' synatx, and what is an example of the 'new' syntax?

Thanks :)
Link to comment
Share on other sites

I guess what they mean by "old syntax" is the use of register_globals.

For example if your PHP setup has register_globals enabled, instead of using $_GET['url_var_here'] you used $url_var_here

The "new syntax" is to disable register_gloabls (which is off by default as of PHP4.2.x) and use the new superglobals which are $_GET, $_POST, $_SESSION, $_COOKIE etc

Another new sytax change is the old superglobals which are the $HTTP_*_VARS. For example instead of using $HTTP_GET_VARS you use $_GET instead for accessing vars in the URL. Or instead of $HTTP_POST_VARS your use $_POST etc.
Link to comment
Share on other sites

[quote author=wildteen88 link=topic=111347.msg451290#msg451290 date=1160733889]
I guess what they mean by "old syntax" is the use of register_globals.

For example if your PHP setup has register_globals enabled, instead of using $_GET['url_var_here'] you used $url_var_here

The "new syntax" is to disable register_gloabls (which is off by default as of PHP4.2.x) and use the new superglobals which are $_GET, $_POST, $_SESSION, $_COOKIE etc

Another new sytax change is the old superglobals which are the $HTTP_*_VARS. For example instead of using $HTTP_GET_VARS you use $_GET instead for accessing vars in the URL. Or instead of $HTTP_POST_VARS your use $_POST etc.
[/quote]

I dunno if that's what the other person was talking about as my version of the book only uses the current superglobals.  I think it may have something to do with 'arrow' syntax ($something -> something) that I see in some people's code.  How does that kind of thing work?
Link to comment
Share on other sites

[quote author=Jenk link=topic=111347.msg451328#msg451328 date=1160741510]
they may have been referring to short tag '<?'

Wihtout an example it's difficult to say :p
[/quote]

Yeah, and of course the post I originally referred to didn't have any examples, only a passing mention of old vs. new syntax.

Oh well, so long as I can get my scripts to work, it doesn't really matter. :)
Link to comment
Share on other sites

the arrow syntax isn't technically old, that's just object-oriented syntax.  you refer to methods and variables that belong to objects using $object_name->method().

as for "old" syntax, there have been small changes between PHP versions (obviously).  the biggest is the superglobals by far, and if those are fine in your book, i can't see any reason to be concerned.  i myself haven't progressed to using PHP 5 yet, so i can't comment there, but apart from that it's probably just function parameter orders, etc.
Link to comment
Share on other sites

Perhaps they refer to use of classes with the following:

[code]<?php

class Foo

    var $bar;

    // constructor
    function Foo()
    {
        $this->bar = 'foobar';
    }
}

?>[/code]

as opposed to php5 syntax:
[code]<?php

class Foo
{
    private $bar;

    public function __construct()
    {
        $this->bar = 'foobar';
    }
}

?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.