To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Upgrading PHP

Upgrading PHP Issues concerning PHP version upgrades and future releases

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-07-2004, 12:35 PM   #1
PHPGuru2
Member
 
Join Date: Mar 2003
Posts: 77
PHP 4 Classes in PHP 5

I have a lot of Classes written in PHP 4.3.x. (no 'public' / 'private' definitions, no __constructor/destructor etc.)

I was wondering if PHP 4 Classes work with PHP 5. I know PHP 5 has back-compatibility but I'm not really sure if they all work.

I think PHP 5 handles pass-by-reference values (&$var) differently from PHP 4.

Any answers??
PHPGuru2 is offline   Reply With Quote
Old 07-07-2004, 03:11 PM   #2
ahundiak
Bright Member
 
ahundiak's Avatar
 
Join Date: Aug 2002
Posts: 1,608
In most cases your PHP4 classes will work unchanged under PHP5. And while PHP5 do longer requires the use of & for passing an object by reference, it does not hurt to do so.
ahundiak is offline   Reply With Quote
Old 07-07-2004, 03:30 PM   #3
PHPGuru2
Member
 
Join Date: Mar 2003
Posts: 77
Thanks for your reply.

What's the exception that you may have to modify your code?? Do you have an example of that?
PHPGuru2 is offline   Reply With Quote
Old 07-07-2004, 05:37 PM   #4
ahundiak
Bright Member
 
ahundiak's Avatar
 
Join Date: Aug 2002
Posts: 1,608
You might want to review this:
http://www.php.net/zend-engine-2.php

Obviously if your PHP4 class had a method called __construct() then you will have problems.

A more subtle issue is that objects are now always passed by reference. Your code may have depended upon a copy being created. For example:
PHP Code:
class Foo
{
  
public $bar = 1;
}
function
process_foo($object)
{
  
$object->bar = 2;
}
$object = new Foo();
echo
"Bar is $object->bar\n";
process_foo($object);
echo
"Bar is $object->bar\n";
The code will produce different results under PHP4 and PHP5 because in PHP4, a copy of $object will be created and locally modified in process_foo while in PHP5 the object itself will be modified.
ahundiak is offline   Reply With Quote
Old 07-13-2004, 02:10 PM   #5
PHPGuru2
Member
 
Join Date: Mar 2003
Posts: 77
pass by reference

Quote:
In most cases your PHP4 classes will work unchanged under PHP5.
And while PHP5 do longer requires the use of & for passing an object by reference,
it does not hurt to do so.
Is object the only thing passed by reference?
or are primitives also passed by reference?
If so then I suspect that the following code
does not work since $foo is initialized in the
parameter (it's not referenced)?

PHP Code:
function foo($foo = "")
{
     echo
$foo;
}
PHPGuru2 is offline   Reply With Quote
Old 07-13-2004, 07:01 PM   #6
ahundiak
Bright Member
 
ahundiak's Avatar
 
Join Date: Aug 2002
Posts: 1,608
Not sure I understand your question.
Only objects are implicitly passed by reference in PHP5. Other types (arrays, strings) are still passed by copy. However, you can explicitly pass other types by reference using the & operator. No change from PHP4.
ahundiak is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 01:53 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.