CodeIgniter Forums
Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7)
+--- Forum: Addins (https://forum.codeigniter.com/forumdisplay.php?fid=13)
+--- Thread: Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 (/showthread.php?tid=69505)

Pages: 1 2


Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - koficypher - 12-05-2017

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


RE: Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - Narf - 12-06-2017

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.


RE: Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - InsiteFX - 12-06-2017

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...


RE: Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - koficypher - 12-06-2017

(12-06-2017, 06: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



RE: Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - InsiteFX - 12-06-2017

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

PHP Code:
(is_array($module)) ? list($module$params) = $this->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.


RE: Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - koficypher - 12-06-2017

(12-06-2017, 08: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


RE: Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - InsiteFX - 12-06-2017

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.


RE: Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - koficypher - 12-06-2017

(12-06-2017, 09: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


RE: Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - ivantcholakov - 12-06-2017

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;
}
//



RE: Deprecation Error with Wiredesign's HMVC extension on PHP 7.2 - gusti - 02-08-2018

i have got the same error