0

Below the code which works as expected before I try to use key while iteration. As I do it, I see an error: "Allowed memory size of 1073741824 bytes exhausted (tried to allocate 9223372043239833600 bytes)". See at the required memory size, it looks monstrous.

The getModules returns an associative array, $id is a string.

Any idea about possible reasons?

 foreach (Yii::$app->getModules() as $id => $module) { echo '<pre>'; var_dump(gettype($module)); if (gettype($module) =='array') { var_dump($module); } else if (gettype($module) =='object') { var_dump(get_class($module)); } //var_dump($id); // <-- We have problems when try to uncomment this echo '</pre>'; } 

php -v:

PHP 7.0.33-25+0~20200225.32+debian9~1.gbpa11893 (cli) (built: Feb 25 2020 13:16:41) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.33-25+0~20200225.32+debian9~1.gbpa11893, Copyright (c) 1999-2017, by Zend Technologies 

UPDATED: I just opened and saved the modules array via ssh and the bug disappears. I have no guess what it was. Looks like an SSD glitch.

6
  • how many modules you have ? Commented Apr 10, 2020 at 15:09
  • 30. In this array one item is an instance of lightweight module, others are associative arrays, most of them have only one item. Commented Apr 10, 2020 at 15:14
  • Yii::$app->getModules() keep it in some variable and then run loop for that variable, and show the result of Yii::$app->getModules(). Commented Apr 10, 2020 at 15:16
  • Can't do it. Got same error while trying to dump the array in a file. Seems the key is not to blame? I must search a reason the in module instance. Commented Apr 10, 2020 at 15:35
  • Do you have the same issue with only row with a var_dump($module) in the foreach-loop? Commented Apr 10, 2020 at 15:46

2 Answers 2

1

The problem that you allways reload all your module each times ou execute the foreach.

Add a variable before to store your modules list, and that's ok.

The corrected code :

$listOfModules = Yii::$app->getModules(); foreach ( $listOfModules as $id => $module) { echo '<pre>'; var_dump(gettype($module)); if (gettype($module) =='array') { var_dump($module); } else if (gettype($module) =='object') { var_dump(get_class($module)); } //var_dump($id); // <-- We have problems when try to uncomment this echo '</pre>'; } 
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I got it and have this code changed already but this editing has no effect. I still have the code crashed when I use $id.
you sure id was string ? and not something more big ?
It must contains only items from config file. I can't imagine how something big can be added to
0

This was an opcache problem. I edited and saved some files but the bug appeared here and there on site pages. So I got that the reason is the cache and just executed opcache_reset().

Hope this solution will be useful for somebody else.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.