Title: Fatal error ($array) cannot be empty in /class-sensei-lesson.php:383
Last modified: October 14, 2024

---

# Fatal error ($array) cannot be empty in /class-sensei-lesson.php:383

 *  Resolved [KZNCraig](https://wordpress.org/support/users/kzncraig/)
 * (@kzncraig)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/)
 * Hi, a customer alerted me to a “There has been a critical error on this website”
   WP error.
 * I checked the PHP error logs and see this error that was logged after the above
   error.
 * [14-Oct-2024 06:47:45 UTC] PHP Fatal error: Uncaught ValueError: array_rand():
   Argument #1 ($array) cannot be empty in /home/africanreptilesv/public_html/wp-
   content/plugins/sensei-lms/includes/class-sensei-lesson.php:3834
 * Kindly advise.
 * Many thanks.
    -  This topic was modified 1 year, 7 months ago by [KZNCraig](https://wordpress.org/support/users/kzncraig/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ffatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Support [Deric (a11n)](https://wordpress.org/support/users/dericleeyy/)
 * (@dericleeyy)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18073714)
 * Are you able to reproduce this issue consistently?
 * Could you try these steps to temporarily disable all plugins and revert to a 
   default theme?
    1. Install [Health Check](https://wordpress.org/plugins/health-check/) plugin on
       your site
    2. Download and install [Twenty Twenty-Three](https://wordpress.org/themes/twentytwentythree/)
       on your site if not installed already
    3. Go to Installed Plugins. Click Troubleshoot on Sensei
    4. Try viewing the Course to reproduce the error
    5. Once you are done, go back to wp-admin and disable troubleshooting mode through
       the top bar.
 *  Thread Starter [KZNCraig](https://wordpress.org/support/users/kzncraig/)
 * (@kzncraig)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18084047)
 * Thank you for your response so far.
 * This is a live environment so I cannot easily disable plugins and change theme.
   The troubleshoot option is not available.
 * All plugins are up to date and WordPress core is up to date.
 * **I can reproduce the error my side.** So it happens for me (the developer), 
   and for the client.
 * The error is pretty clear as it says: “**Array cannot be empty**” which is triggered
   in a file called **class-sensei-lesson.php** on line 38
 * `PHP Fatal error: Uncaught ValueError: array_rand(): Argument #1 ($array) cannot
   be empty in */plugins/sensei-lms/includes/class-sensei-lesson.php:38`
 * When I open this file line 38 shows php **comments **within a class called “class
   Sensei_Lesson {” – not code. So it is very confusing.
 * Is there a chance I can get direct email ticket support?
 *  Plugin Support [Cara](https://wordpress.org/support/users/dcka/)
 * (@dcka)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18087533)
 * [@kzncraig](https://wordpress.org/support/users/kzncraig/) Email support is available
   with a paid license, so please feel free to [reach out](https://senseilms.com/contact/)
   if you have one. Otherwise, we’re happy to continue helping here.
 * > This is a live environment so I cannot easily disable plugins and change theme.
   > The troubleshoot option is not available.
 * The [Health Check](https://wordpress.org/plugins/health-check/) plugin recommended
   earlier enables you to deactivate plugins and the theme without affecting how
   it appears to users. Once that is installed and active on the site, you should
   be able to click Troubleshoot on Sensei.
 * Alternatively, you can create a staging version of your client’s site where you
   should be able to troubleshoot more thoroughly. Many hosts provide a staging 
   service, where you can do testing without affecting the live site. You can ask
   your host about this. 
 * If they don’t give you a staging site, you could try WP Staging or Duplicator:
    - [https://wordpress.org/plugins/wp-staging/](https://wordpress.org/plugins/wp-staging/)
    - [https://wordpress.org/plugins/duplicator/](https://wordpress.org/plugins/duplicator/)
 *  Plugin Author [Donna Peplinskie (a11n)](https://wordpress.org/support/users/donnapep/)
 * (@donnapep)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18089180)
 * Hi [@kzncraig](https://wordpress.org/support/users/kzncraig/),
 * > **I can reproduce the error my side.**
 * Are you able to share steps to reproduce? Are you viewing a lesson or quiz when
   the error occurs?
 * By looking at the code, I’m guessing that you may have the Classic Editor plugin
   activated. Can you confirm? If so, can you please share screenshots of the Quiz
   Settings and Quiz Questions meta boxes for the problematic lesson / quiz?
 * > When I open this file line 38 shows php **comments **within a class called “
   > class Sensei_Lesson {” – not code. So it is very confusing.
 * In your original message the fatal error indicated the issue was on line 3834,
   which does call `array_rand`.
 *  Plugin Support [Jay](https://wordpress.org/support/users/bluejay77/)
 * (@bluejay77)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18105788)
 * Hi there,
 * It has been a while since we have heard from you, so I’m marking this topic as
   resolved.
 * But if you have any further questions or need some more help, you’re welcome 
   to reply here or open another thread.
 *  [joncampbell](https://wordpress.org/support/users/joncampbell/)
 * (@joncampbell)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18233249)
 * On our site when we remove a user from a course, here is the relevant stack trace:
 * class-sensei-lesson.php(3832): array_rand(Array, 0)
   class-sensei-utils.php(733):
   Sensei_Lesson->lesson_quiz_questions(‘10055172’)class-sensei-utils.php(811): 
   Sensei_Utils::sensei_get_quiz_questions(10055172)class-sensei-utils.php(660):
   Sensei_Utils::sensei_delete_quiz_answers(10055172, 3405)class-sensei-utils.php(
   706): Sensei_Utils::sensei_remove_user_from_lesson(10055171, 3405, true)class-
   sensei-utils.php(2818): Sensei_Utils::sensei_remove_user_from_course(85579, 3405)
   Seems like to remove the user from the course it wants to delete their quiz answers
   but to do that it gets the lesson_quiz_questions but in our case the $questions_array
   used in this code is empty:
 * $selected_questions = _array\_rand_(
   $questions_array,$show_questions > $questions_count?
   $questions_count : $show_questions);And it errors out because it can’t randomize
   an empty array.
 *  Plugin Support [Deric (a11n)](https://wordpress.org/support/users/dericleeyy/)
 * (@dericleeyy)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18233759)
 * [@joncampbell](https://wordpress.org/support/users/joncampbell/)
 * Could you try these steps to temporarily disable all plugins and revert to a 
   default theme?
    1. Install [Health Check](https://wordpress.org/plugins/health-check/) plugin on
       your site
    2. Download and install [Twenty Twenty-Five](https://wordpress.org/themes/twentytwentyfive/)
       on your site if not installed already
    3. Go to Installed Plugins. Click Troubleshoot on Sensei
    4. Try removing a user from a course
    5. Once you are done, go back to wp-admin and disable troubleshooting mode through
       the top bar.
 *  [joncampbell](https://wordpress.org/support/users/joncampbell/)
 * (@joncampbell)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18246256)
 * [@dericleeyy](https://wordpress.org/support/users/dericleeyy/) 
   I installed Twenty
   Twenty-Five and Health Check and did the troubleshooting.I then went to the Students
   area of the admin and Reset Progress on a user and it causes a fatal error still:[
   15-Jan-2025 20:03:18 UTC] PHP Fatal error: Uncaught ValueError: array_rand():
   Argument #1 ($array) cannot be empty in /wp-content/plugins/woothemes-sensei/
   plugins/sensei-lms/includes/class-sensei-lesson.php:3832Stack trace: 0 /wp-content/
   plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-lesson.php(
   3832): array_rand(Array, 0) 1 /wp-content/plugins/woothemes-sensei/plugins/sensei-
   lms/includes/class-sensei-utils.php(733): Sensei_Lesson->lesson_quiz_questions(‘
   10055172’) 2 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/
   class-sensei-utils.php(811): Sensei_Utils::sensei_get_quiz_questions(10055172)
   3 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-
   utils.php(660): Sensei_Utils::sensei_delete_quiz_answers(10055172, 3405) 4 /wp-
   content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-utils.
   php(706): Sensei_Utils::sensei_remove_user_from_lesson(10055171, 3405, true) 
   5 /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-sensei-
   utils.php(2818): Sensei_Utils::sensei_remove_user_from_course(85579, 3405) 6 /
   wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/rest-api/class-
   sensei-rest-api-course-progress-controller.php(81): Sensei_Utils::reset_course_for_user(
   85579, 3405) 7 /wp-includes/rest-api/class-wp-rest-server.php(1292): Sensei_REST_API_Course_Progress_Controller-
   >batch_delete_items(Object(WP_REST_Request)) 8 /wp-includes/rest-api/class-wp-
   rest-server.php(1125): WP_REST_Server->respond_to_request(Object(WP_REST_Request),‘/
   sensei-interna…’, Array, NULL) 9 /wp-includes/rest-api/class-wp-rest-server.php(
   439): WP_REST_Server->dispatch(Object(WP_REST_Request)) 10 /wp-includes/rest-
   api.php(449): WP_REST_Server->serve_request(‘/sensei-interna…’) 11 /wp-includes/
   class-wp-hook.php(324): rest_api_loaded(Object(WP)) 12 /wp-includes/class-wp-
   hook.php(348): WP_Hook->apply_filters(”, Array) 13 /wp-includes/plugin.php(565):
   WP_Hook->do_action(Array) 14 /wp-includes/class-wp.php(418): do_action_ref_array(‘
   parse_request’, Array) 15 /wp-includes/class-wp.php(813): WP->parse_request(”)
   16 /wp-includes/functions.php(1336): WP->main(”) 17 /wp-blog-header.php(16): 
   wp() 18 /index.php(17): require(‘/Users/jon…..’) 19 {main}
 * thrown in /wp-content/plugins/woothemes-sensei/plugins/sensei-lms/includes/class-
   sensei-lesson.php on line 3832
    -  This reply was modified 1 year, 4 months ago by [joncampbell](https://wordpress.org/support/users/joncampbell/).
 *  Plugin Support [Cara](https://wordpress.org/support/users/dcka/)
 * (@dcka)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18248965)
 * [@joncampbell](https://wordpress.org/support/users/joncampbell/) So far, we haven’t
   been able to replicate the issue on a demo site generated from [here](https://app.instawp.io/launch?t=sensei-lms-demo-site).
   Can you let us know which version of Sensei LMS you’re using? Can you please 
   make sure you’re using the [latest version available](https://wordpress.org/plugins/sensei-lms/)?
 * If the issue persists on the latest version, please also share the following 
   from the site:
    - PHP version
    - WordPress version
    - Sensei LMS version
 * In any case, we’ll open an issue for this so we can investigate further.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Fatal error ($array) cannot be empty in /class-sensei-lesson.php:383’
is closed to new replies.

 * ![](https://ps.w.org/sensei-lms/assets/icon-128x128.gif?rev=2914239)
 * [Sensei LMS - Online Courses, Quizzes, & Learning](https://wordpress.org/plugins/sensei-lms/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/sensei-lms/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/sensei-lms/)
 * [Active Topics](https://wordpress.org/support/plugin/sensei-lms/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sensei-lms/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sensei-lms/reviews/)

 * 9 replies
 * 6 participants
 * Last reply from: [Cara](https://wordpress.org/support/users/dcka/)
 * Last activity: [1 year, 4 months ago](https://wordpress.org/support/topic/fatal-error-array-cannot-be-empty-in-class-sensei-lesson-php383/#post-18248965)
 * Status: resolved