Tips to Upgrade 1.3.6 to PHP 8.4

Forum
Last Post
Threads / Messages

Kesstryl

Member
Member
Joined
Feb 22, 2012
Messages
230
Points
28
Mysidian Dollar
11,974
My webhost stopped supporting PHP 8.0 and so I had to do acrobatics to upgrade Mysidia to 8.4

This guide is not comprehensive because I don't remember all the stuff I needed to do and I'm bad at documentation. I can leave some tips though. This will be ongoing, and I will help if you attenpt this and have errors.

Tip 1.

Use this piece of code reight above a function method to reduce some of the errors with incorrect return types:

#[\ReturnTypeWillChange]
public function foo(): mixed

Note: this might be depreciated at some point, and it will not fix all errors, so you will have to learn the next tip.


Tip 2.

Where errors are generated with functions asking for specific return types, you will need to do something like this. I'm going to use the example in core\native\mysstring

around line 495ish there is this function which gave me a huge headache and was nearly impossible to track the location of, but I'm giving it to you so you don't have the problems I did.

/**
* Return the key of the current element.
* @return int
*/
public function key()
{
return $this->_index;
}

Here is my fixed code
Code:
    /**
     * Return the key of the current element.
     * @return int
     */
    public function key(): int
    {
        return $this->_index;
    }

Notice that I put : int after the parenthesis in the function name. This is now the standard way to do functions and methods in modern PHP. I knew to put int because in the comment it says * @return int so this is the type that function is supposed to return. This will force templates to hash with integers instead of float numbers.

When you go through all the errors and find their locations, look at the comment on that bit of code to find out the return type, and then after the parenthesis use a colon and the return type. Here is a list of return types below:

: int
: string
: void
: mixed
: bool
: array
: float
: callable
: interfaces

If the * @return is trying to return a function, I don't think you need to add anything.

You won't be required to go through every single function in the entire code to get it to work, but you will need to test everything to see where it's needed. Most of the code I encountered was in resources, and some of the models, but I'm still testing things myself so I'm sure I will hit other spots. Eventually you should do this to all the functions for forward compatability, but for now only focus on the errors and warnings.
 
Last edited:
Tip 3.

Some functions pass null when a return type is expected, and this is not allowed in modern PHP anymore. We will need to fix functions that pass null to accept null values.

Example model\domainmodel\userprofile

public function __construct($uid, $dto = NULL, User $user = NULL){

I had to change this to:

public function __construct($uid, $dto = NULL, User|NULL $user = NULL){

Tip 4. More to come as needed
 
Last edited:
A solid list in general, it is nice to see how Mys v1.3.x can work with latest PHP version.

And a few comments:

For tip #2, can you show what is the error message you get? I do not recall missing return type declaration should trigger any errors, as PHP type hinting is completely optional.

For tip #3, I believe this is not a fatal error but more of a deprecated warning/notice? In this case, it is quicker and easier to just add this to the index.php page to disable deprecation messages:

PHP:
error_reporting(E_ALL & ~E_DEPRECATED);

This should get rid of the deprecated messages on PHP 8.4, though the technique will not work for PHP 9+ anymore as the deprecation will become error.
 
A solid list in general, it is nice to see how Mys v1.3.x can work with latest PHP version.

And a few comments:

For tip #2, can you show what is the error message you get? I do not recall missing return type declaration should trigger any errors, as PHP type hinting is completely optional.

For tip #3, I believe this is not a fatal error but more of a deprecated warning/notice? In this case, it is quicker and easier to just add this to the index.php page to disable deprecation messages:

PHP:
error_reporting(E_ALL & ~E_DEPRECATED);

This should get rid of the deprecated messages on PHP 8.4, though the technique will not work for PHP 9+ anymore as the deprecation will become error.
Actually E_DEPRECIATED is depreciated, LOL. I had to change that to simply E_ALL, and it will not stop warnings and fatal errors anyway. A lot has changed in the latest versions of PHP that is breaking some code.

I'm updating a copy of vanilla Mysidia upgraded to PHP 8.4 for others to use if you would like me to send it to you for review and testing. Maybe it could be a final update for the Mys v1.3.x series as a hold over until version 4.
 
Actually E_DEPRECIATED is depreciated, LOL. I had to change that to simply E_ALL, and it will not stop warnings and fatal errors anyway. A lot has changed in the latest versions of PHP that is breaking some code.

I'm updating a copy of vanilla Mysidia upgraded to PHP 8.4 for others to use if you would like me to send it to you for review and testing. Maybe it could be a final update for the Mys v1.3.x series as a hold over until version 4.
Yeah I am just wondering what are the errors you got that you ended up fixing by adding method return type hint, to me this seems rather strange. Will be great you can provide more information, otherwise I can try testing it myself at some point to see what happens.

Regarding depredation, yes I’d agree it is better to fix it the hard way since turning off error report will not work in PHP 9+ anyway.

A new minor version for Mys v1.3.x to address this issue is definitely a possibility, I will think about it during the rest of summer.
 
Yeah I am just wondering what are the errors you got that you ended up fixing by adding method return type hint, to me this seems rather strange. Will be great you can provide more information, otherwise I can try testing it myself at some point to see what happens.

Regarding depredation, yes I’d agree it is better to fix it the hard way since turning off error report will not work in PHP 9+ anyway.

A new minor version for Mys v1.3.x to address this issue is definitely a possibility, I will think about it during the rest of summer.
The type of errors I was getting is addressed on this page for depreciations for PHP 8.1 https://php.watch/versions/8.1/internal-method-return-types
 
We sure have needed this for a very, very long time. I have struggled with upgrading for years, its so good someone finally got it going!
 
I'm updating a copy of vanilla Mysidia upgraded to PHP 8.4 for others to use if you would like me to send it to you for review and testing. Maybe it could be a final update for the Mys v1.3.x series as a hold over until version 4.





1.4.0? ... Is that still happening? It's been years now. Be great if so ...
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,314
Messages
33,325
Members
1,612
Latest member
BubbaSawyerIsACutie
BETA
Top