Jump to content


Photo

General syntax question


  • Please log in to reply
6 replies to this topic

#1 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 12 October 2006 - 10:07 PM

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 :)
Using 'global' is a sign of doing it wrong

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 October 2006 - 10:04 AM

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.

#3 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 13 October 2006 - 11:42 AM

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.


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?
Using 'global' is a sign of doing it wrong

#4 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 13 October 2006 - 12:11 PM

they may have been referring to short tag '<?'

Wihtout an example it's difficult to say :P

#5 KevinM1

KevinM1
  • Moderators
  • Snarkimus Prime
  • 5,248 posts

Posted 13 October 2006 - 02:19 PM

they may have been referring to short tag '<?'

Wihtout an example it's difficult to say :P


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. :)
Using 'global' is a sign of doing it wrong

#6 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 13 October 2006 - 02:25 PM

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.

#7 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 13 October 2006 - 03:26 PM

Perhaps they refer to use of classes with the following:

<?php

class Foo

    var $bar;

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

?>

as opposed to php5 syntax:
<?php

class Foo
{
    private $bar;

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

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users