Re: [PHP] PHP4 vs PHP5 classes

2008-07-30 Thread Larry Garfield
On Wednesday 30 July 2008 12:44:46 am Robert Cummings wrote:

 It's unfortunate that PHP5 decided to throw a Strict Standards exception
 when you include both style constructors. For instance, I'm certain at
 one point the following was recommended:

 ?php
 class Foo
 {
 function __construct()
 {
 }

 function Foo()
 {
 self::__construct();
 }
 }
 ?

 This was perfectly compatible with PHP5 and gave precedence to the PHP5
 constructor style. Somewhere along the line though PHP5 started
 spouting:

 Strict Standards: Redefining already defined constructor

 So I just completely removed the PHP5 style constructors from my code
 and use the PHP4 style since then there are no exceptions. Mark my words
 though... at some point PHP will start spewing an E_DEPRECATED for PHP4
 style constructor *lol*.

 Cheers,
 Rob.

Well, since PHP 4 has been officially retired as of the start of this year and 
the final-forever release of PHP 4 (4.4.9) is due by 08/08/08, I don't think 
that's much of an issue.  If you're still coding to PHP 4, you're pretty much 
on your own and need to move into this century.

Especially given the different way objects are handled between PHP 4 and PHP 
5, trying to support a dead version of PHP is simply not worth the effort.  
Go PHP 5 and don't look back.  (And if you're on a web host that is still on 
PHP 4, I recommend you switch to a web host that is not doomed to go out of 
business within the next year, because I predict it will.)

-- 
Larry Garfield
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-30 Thread Robert Cummings
On Wed, 2008-07-30 at 01:16 -0500, Larry Garfield wrote:
 On Wednesday 30 July 2008 12:44:46 am Robert Cummings wrote:
 
  It's unfortunate that PHP5 decided to throw a Strict Standards exception
  when you include both style constructors. For instance, I'm certain at
  one point the following was recommended:
 
  ?php
  class Foo
  {
  function __construct()
  {
  }
 
  function Foo()
  {
  self::__construct();
  }
  }
  ?
 
  This was perfectly compatible with PHP5 and gave precedence to the PHP5
  constructor style. Somewhere along the line though PHP5 started
  spouting:
 
  Strict Standards: Redefining already defined constructor
 
  So I just completely removed the PHP5 style constructors from my code
  and use the PHP4 style since then there are no exceptions. Mark my words
  though... at some point PHP will start spewing an E_DEPRECATED for PHP4
  style constructor *lol*.
 
  Cheers,
  Rob.
 
 Well, since PHP 4 has been officially retired as of the start of this year 
 and 
 the final-forever release of PHP 4 (4.4.9) is due by 08/08/08, I don't think 
 that's much of an issue.  If you're still coding to PHP 4, you're pretty much 
 on your own and need to move into this century.
 
 Especially given the different way objects are handled between PHP 4 and PHP 
 5, trying to support a dead version of PHP is simply not worth the effort.  
 Go PHP 5 and don't look back.  (And if you're on a web host that is still on 
 PHP 4, I recommend you switch to a web host that is not doomed to go out of 
 business within the next year, because I predict it will.)

My code works fine in PHP5, it has worked fine since before PHP5
launched an official version. That said, I do still code to PHP4
compatibility... and I am certainly NOT alone. Also, for what it's
worth, at one point in this century PHP4 was the only option since
PHP5 was released mid 2004, therefore there is nothing about this
century that makes it the exclusive territory of PHP5. Moving along
though, it's also worth noting, that web hosts worth their salt, provide
access to both PHP4 AND PHP5 thus allowing the use of whichever version
their customers damn well please. And I will bet you a hundred bucks
there will still be PHP4 hosts in existence in another year.

http://www.nexen.net/images/stories/phpversion/200804/evolution.milieu.en.png

In April (yes I know it's now July) PHP4 was still kicking PHP5's ass.
Not bad for a dead version.

And before anyone gets their panties in a bunch, I'm not advocating
picking up and starting to work with PHP4. But I'm certainly not so full
of hubris to think just because someone said jump (or GOPHP5 if you
will) that every Bill, Bob, and Betty on the Intertubes is going to
switch from PHP4 to PHP5. There's a very real cost to switching, and if
it isn't necessary then (speaking frankly) fuckit!

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-29 Thread Chris
[EMAIL PROTECTED] wrote:
 Since the Players method is a constructor, it's more about how you set
 the object(s) up.

 What does the loop look like before you create a new object?

 
 Well see here is where it gets messy! This is not my code - I've ported a
 phpnuke module over to dragonflycms.
 
 The $players object is created before the loop:
 $players = new Players($lid);

snip

Which means the code is only executed once since it's in the
constructor. It's not changing per loop because you're not calling the code.

Maybe setting $this-max should be done in

fetchSelectData

since that's what is causing/creating your loop.

-- 
Postgresql  php tutorials
http://www.designmagick.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-29 Thread jeff . mills


 Since the Players method is a constructor, it's more about how you set
 the object(s) up.

 What does the loop look like before you create a new object?


Well see here is where it gets messy! This is not my code - I've ported a
phpnuke module over to dragonflycms.

The $players object is created before the loop:
$players = new Players($lid);

The loop is quite big, but here is the important part:

-SNIP-
while (list($pid, $name, $gsid, $stat) = $players-fetchSelectData()) {
  if (DEBUG_LEAGUE == YES) echo trtd colspan=\22\\$maxcol =
$maxcol | \$pid = $pid | \$name = $name | \$gsid = $gsid | \$stat =
$stat/td/tr\$
  $noplayer=0;
  if ($prevgsid != $gsid) {
 $prevgsid = $gsid;
 $players-selectHeaders($gsid);
 if (DEBUG_LEAGUE == YES) var_dump($players);
 displayPlayerSetupRow($players,
.getlink($module).amp;file=indexamp;mode=$modeamp;lid=$lidamp;sid=$sidamp;gsid=$gsid,
$order);
  }
-SNIP-

function displayPlayerSetupRow is also very big, but here it is up to the
troublesome $players-max call:

-SNIP-
function displayPlayerSetupRow($players, $go=, $prevorder=0) {
   global $bgcolor2;

   if ($prevorder==)
  $prevorder=0;

   $urlstart=;
   $urlend=;
   $max = $players-max();

-SNIP-

Then we enter class Players as previously mentioned:

-SNIP-
class Players extends dynamicTable {
   var $setup;
   var $lid;
   var $size;
   var $max;
   var $data;
   var $data_result;
   var $data_index;
   var $player_stats_result;
   var $player_stats_data;
   var $player_stats_index;
   var $player_stats_start;
   var $player_type_result;

   function Players($lid) {
  global $prefix, $db;

  /*
   * Find max size of rows
   */

  $this-lid = $lid;
  $this-max=0;
  $result = $db-sql_query(select * from  . $prefix .
_league_games_setup where lid = $lid);
  while (($rows = $db-sql_fetchrow($result))) {
 $c=0;
 for ($i=3; $i  23; $i++) {
  if ($rows[$i] != )
 $c++;
 }
 if ($c  $this-max)
$this-max = $c;
  }

  $this-index = 3;
   }

   function name() {
  return ($this-setup['name']);
   }

   function max() {
return ($this-max);
   }
-SNIP-






 --
 Postgresql  php tutorials
 http://www.designmagick.com/

 --
 This email has been scanned for viruses and dangerous content by
 Sydney Technology Solutions MailMaster Email Protection Services.

 For more information please visit http://www.sydneytech.com.au
 :Scanned by MailMaster1:





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-29 Thread jeff . mills


 The $players object is created before the loop:
 $players = new Players($lid);

 snip

 Which means the code is only executed once since it's in the
 constructor. It's not changing per loop because you're not calling the
 code.

 Maybe setting $this-max should be done in

 fetchSelectData

 since that's what is causing/creating your loop.

Thanks Chris, I will give that a shot.
Just to confirm, this script works just fine in php4, so do we put that
down to pure luck, or has there been a change in php5 that will be causing
it?




 --
 Postgresql  php tutorials
 http://www.designmagick.com/

 --
 This email has been scanned for viruses and dangerous content by
 Sydney Technology Solutions MailMaster Email Protection Services.

 For more information please visit http://www.sydneytech.com.au
 :Scanned by MailMaster1:





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-29 Thread jeff . mills

 Maybe setting $this-max should be done in

 fetchSelectData

 since that's what is causing/creating your loop.


Thanks Chris, I copied the code into the fetchSelectData function and it
seems to be working fine now!
Just need to test removing the code from the constructor to make sure its
still working, and also test that php4 is still working.

I'm just concerned that the code might also be called from somewhere else.

You've cured my headache!


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-29 Thread Chris
[EMAIL PROTECTED] wrote:
 The $players object is created before the loop:
 $players = new Players($lid);
 snip

 Which means the code is only executed once since it's in the
 constructor. It's not changing per loop because you're not calling the
 code.

 Maybe setting $this-max should be done in

 fetchSelectData

 since that's what is causing/creating your loop.
 
 Thanks Chris, I will give that a shot.
 Just to confirm, this script works just fine in php4, so do we put that
 down to pure luck, or has there been a change in php5 that will be causing
 it?

No idea why it works in php4 - if you're only calling the Players
method once (or through the constructor) it should have behaved the same
in php4.

-- 
Postgresql  php tutorials
http://www.designmagick.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-29 Thread Jim Lucas

[EMAIL PROTECTED] wrote:

Maybe setting $this-max should be done in

fetchSelectData

since that's what is causing/creating your loop.



Thanks Chris, I copied the code into the fetchSelectData function and it
seems to be working fine now!
Just need to test removing the code from the constructor to make sure its
still working, and also test that php4 is still working.

I'm just concerned that the code might also be called from somewhere else.

You've cured my headache!




Don't forget that in PHP5, the constructor named has changed.  In PHP4 it 
called a method with the same name as the class.  But, in PHP5, it looks for 
__construct() instead.


I workaround that I use is this:

?php

class myClass {

  function __construct() {
  }

  function myClass() {
$this-__construct();
  }

}

?

With this type of construct, your classes will initialize the same between 
PHP4 and PHP5.


--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-29 Thread Chris

 Don't forget that in PHP5, the constructor named has changed.  In PHP4
 it called a method with the same name as the class.  But, in PHP5, it
 looks for __construct() instead.

If __construct doesn't exist then it falls back to the php4 way - makes
it backwards compatible :)

-- 
Postgresql  php tutorials
http://www.designmagick.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-29 Thread Jim Lucas

Chris wrote:

Don't forget that in PHP5, the constructor named has changed.  In PHP4
it called a method with the same name as the class.  But, in PHP5, it
looks for __construct() instead.


If __construct doesn't exist then it falls back to the php4 way - makes
it backwards compatible :)



But, if people want to code to php5 standards and beyond, then I would 
recommend always using the __construct() method to construct your class. 
 Then make it work in php4.  Not the other way around.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-29 Thread Robert Cummings
On Tue, 2008-07-29 at 22:26 -0700, Jim Lucas wrote:
 Chris wrote:
  Don't forget that in PHP5, the constructor named has changed.  In PHP4
  it called a method with the same name as the class.  But, in PHP5, it
  looks for __construct() instead.
  
  If __construct doesn't exist then it falls back to the php4 way - makes
  it backwards compatible :)
  
 
 But, if people want to code to php5 standards and beyond, then I would 
 recommend always using the __construct() method to construct your class. 
   Then make it work in php4.  Not the other way around.

It's unfortunate that PHP5 decided to throw a Strict Standards exception
when you include both style constructors. For instance, I'm certain at
one point the following was recommended:

?php
class Foo
{
function __construct()
{
}

function Foo()
{
self::__construct();
}
}
?

This was perfectly compatible with PHP5 and gave precedence to the PHP5
constructor style. Somewhere along the line though PHP5 started
spouting:

Strict Standards: Redefining already defined constructor

So I just completely removed the PHP5 style constructors from my code
and use the PHP4 style since then there are no exceptions. Mark my words
though... at some point PHP will start spewing an E_DEPRECATED for PHP4
style constructor *lol*.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP4 vs PHP5 classes

2008-07-28 Thread jeff . mills
I have the following code in part of a loop:
$max = $players-max();

Important parts of players class:
class Players extends dynamicTable {
   var $setup;
   var $lid;
   var $size;
   var $max;
   var $data;
   var $data_result;
   var $data_index;
   var $player_stats_result;
   var $player_stats_data;
   var $player_stats_index;
   var $player_stats_start;
   var $player_type_result;

   function Players($lid) {
  global $prefix, $db;

  /*
   * Find max size of rows
   */

  $this-lid = $lid;
  $this-max=0;
echo $this-index;
  $result = $db-sql_query(select * from  . $prefix .
_league_games_setup where lid = $lid);
  while (($rows = $db-sql_fetchrow($result))) {
 $c=0;
 for ($i=3; $i  23; $i++) {
  if ($rows[$i] != )
 $c++;
 }
 if ($c  $this-max)
$this-max = $c;
  }

  $this-index = 3;
   }


   function max() {
return ($this-max);


The most important part of this code to me is:
$this-index = 3;
It is important that this is reset to 3 for the rest of the loop to work
properly.
In PHP4, $this-index is reset to 3 each time the loop happens, but in
PHP5 it is not.
It appears that after the first loop, PHP5 seems to remember the value
of $this-max and therefore does not enter the Players function to set
$this-index = 3. I have run through the script with a debugger, and sure
enough, we only enter function Players once.

Is this normal behaviour for PHP5 vs PHP4?
Is there a way for me to force $this-max to be calculated each time
function max is called?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP4 vs PHP5 classes

2008-07-28 Thread Chris

 I have run through the script with a debugger, and sure
 enough, we only enter function Players once.
 
 Is this normal behaviour for PHP5 vs PHP4?
 Is there a way for me to force $this-max to be calculated each time
 function max is called?

Since the Players method is a constructor, it's more about how you set
the object(s) up.

What does the loop look like before you create a new object?

-- 
Postgresql  php tutorials
http://www.designmagick.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php