• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deprecation Error with Wiredesign's HMVC extension on PHP 7.2

#1
Just until yesterday and until i had upgraded to php 7.2 i got this error saying thIs

PHP Code:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<
h4>A PHP Error was encountered</h4>

<
p>Severity8192</p>
<
p>Message The each() function is deprecatedThis message will be suppressed on further calls</p>
<
p>FilenameMX/Modules.php</p>
<
p>Line Number83</p>


    <
p>Backtrace:</p>
    
        
    
        
    
        
    
        
            <
p style="margin-left:10px">
            
File: /var/www/html/ci_hmvc/application/third_party/MX/Modules.php<br />
            
Line83<br />
            Function: 
each            </p>

        
    
        
            <
p style="margin-left:10px">
            
File: /var/www/html/ci_hmvc/application/third_party/MX/Loader.php<br />
            
Line251<br />
            Function: 
load            </p>

        
    
        
            <
p style="margin-left:10px">
            
File: /var/www/html/ci_hmvc/application/core/MY_Controller.php<br />
            
Line9<br />
            Function: 
module            </p>

        
    
        
            <
p style="margin-left:10px">
            
File: /var/www/html/ci_hmvc/application/modules/home/controllers/Home.php<br />
            
Line8<br />
            Function: 
__construct            </p>

        
    
        
    
        
            <
p style="margin-left:10px">
            
File: /var/www/html/ci_hmvc/index.php
            Line
315<
            Function: require_once 
any ideas on what coukd have gone wrong per the new installation php or i made a mistake somewhere.....

system info: php7.2 on ubuntu 17.10 lamp stack
Reply

#2
You've done nothing wrong, except you haven't really put thought into this before posting about it.

each() is deprecated in PHP 7.2 and the extension you're using uses the function - that's all there's to be said about it.
Reply

#3
This is not TESTED!

But you can try it, if not it will be a start to fixing the depreciated each() function.

Change line 83 or 84 - in third_party/MX/Modules.php -

PHP Code:
(is_array($module)) ? list($module$params) = each($module) : $params NULL

Add this code and see if it will fix the problem for you.

PHP Code:
if (is_array($module))
{
 
   $temp $module;

 
   $module key($temp);
 
   $params current($temp);
 
   
    list
($module$params);
}
else
{
 
   $params NULL;


Remember this is not TESTED...
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#4
(12-06-2017, 07:16 AM)InsiteFX Wrote: This is not TESTED!

But you can try it, if not it will be a start to fixing the depreciated each() function.

Change line 83 or 84 - in third_party/MX/Modules.php -

PHP Code:
(is_array($module)) ? list($module$params) = each($module) : $params NULL

Add this code and see if it will fix the problem for you.

PHP Code:
if (is_array($module))
{
 
   $temp $module;

 
   $module key($temp);
 
   $params current($temp);
 
   
    list
($module$params);
}
else
{
 
   $params NULL;


Remember this is not TESTED...

Thanks for your help and i appreciate it. However i tried it and it seems that the list function needs to be assigned to some variable.
i got this error by the way...
Code:
Type: ParseError

Message: syntax error, unexpected ';', expecting '='

Filename: /var/www/html/ci_hmvc/application/third_party/MX/Modules.php

Line Number: 91

Backtrace:

File: /var/www/html/ci_hmvc/application/core/MY_Router.php
Line: 4
Function: require

File: /var/www/html/ci_hmvc/index.php
Line: 315
Function: require_once
Reply

#5
Alright, here is another one you can try, again not TESTED.

PHP Code:
(is_array($module)) ? list($module$params) = makeEach($module) : $params NULL

// Add this new method to the bottom of the Module.php file.
public function makeEach(&$arr)
{
 
   $key key($arr);

 
   $result = ($key === null
 
       false 
        
: [$keycurrent($arr), 'key' => $key'value' => current($arr)];

 
   next($arr);

 
   return $result;


Add that new method to the bottom of the Module file.
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#6
(12-06-2017, 09:36 AM)InsiteFX Wrote: Alright, here is another one you can try, again not TESTED.

PHP Code:
(is_array($module)) ? list($module$params) = makeEach($module) : $params NULL

// Add this new method to the bottom of the Module.php file.
public function makeEach(&$arr)
{
 
   $key key($arr);

 
   $result = ($key === null
 
       false 
        
: [$keycurrent($arr), 'key' => $key'value' => current($arr)];

 
   next($arr);

 
   return $result;


Add that new method to the bottom of the Module file.
Okay so that worked but i had to do some few changes to  your code.

i made the function you asked me to place at the bottom a static function and called it in that line using Self::makeEach so i ended up having something like this
PHP Code:
(is_array($module)) ? list($module$params) = Self::makeEach($module) : $params NULL
    
public static function 
makeEach(&$arr)
 
   {
         
   $key key($arr);

         
   $result = ($key === null
         
       false 
                
: [$keycurrent($arr), 'key' => $key'value' => current($arr)];

         
   next($arr);

         
   return $result;
    } 

And that did it... Thanks InsiteFX
Reply

#7
Right I just noticed that I left off the $this->

Anyways glad you got it to work I' am sure it will bite some of the other users.
What did you Try? What did you Get? What did you Expect?

Joined the CodeIgniter Community in 2009.          ( Skype: insitfx )
Reply

#8
(12-06-2017, 10:39 AM)InsiteFX Wrote: Right I just noticed that I left off the $this->

Anyways glad you got it to work I' am sure it will bite some of the other users.

haha
Thanks again
Reply

#9
I found a patch in my code about this deprecation. Probably it is based on a snippet I've seen before, but I don't remember from where it has been taken.

Code:
// Modified by Ivan Tcholakov, 21-JAN-2017.
//(is_array($module)) ? list($module, $params) = each($module) : $params = NULL;
if (is_array($module)) {
    list($params, $module) = array(reset($module), key($module));
} else {
    $params = NULL;
}
//
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.