Title: Php error &#8211; Undefined array key &#8220;block&#8221;
Last modified: June 26, 2024

---

# Php error – Undefined array key “block”

 *  Resolved [Hoek](https://wordpress.org/support/users/hoeczek/)
 * (@hoeczek)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/php-error-undefined-array-key-block/)
 * I have php log error like:
 *     ```wp-block-code
       2024/06/26 18:26:17 [error] 231349#231349: *424966 FastCGI sent in stderr: "PHP message: PHP Warning:  Undefined array key "block" in /var/www/test/wp-content/plugins/javascript-notifier/javascript-notifier.php on line 74" while reading upstream, client: IP, server: test.test, request: "GET /blablabla/ HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php8.3-fpm.sock:", host: "blablabla"
       ```
   
 * The error message indicates that the array key `block` is being accessed in the
   plugin’s code without first checking if it exists. Maybe to prevent the PHP warning,
   you can add a check to ensure that the `block` key is defined before using it.
   Here is the modified part of the code in `javascript-notifier.php`:
 *     ```wp-block-code
       add_action( 'wp_footer',        function() {                $settings = get_option( 'javascript_notifier_settings' );                $block = isset($settings['block']) ? $settings['block'] : '';                $style = 'style="background-color:' . $settings['bg_color'] . ';color:' . $settings['fg_color'] . ';font-size:' . $settings['font_size'] . '%;opacity:' . $settings['opacity'] . ';' . $settings['custom_css'] . '"';?><!-- JavaScript Notifier --><?php if( $block ) : ?><div class="javascript_notifier" id="javascript_notifier_block" <?php echo $style; ?>><div id="javascript_notifier_block_2"><div id="javascript_notifier_block_3"><?php else : ?><div class="javascript_notifier" id="javascript_notifier_bar" <?php echo $style; ?>><?php endif; ?><strong><?php echo $settings['message']; ?></strong></div><?php if( $block ) : ?></div></div><?php endif; ?><script id="hide-javascript-notifier-js" type="application/javascript">document.getElementById('javascript_notifier_<?php echo( $block ? 'block' : 'bar' ); ?>').style.setProperty('display', 'none', 'important');</script><!-- End JavaScript Notifier --><?php        }, 1 );
       ```
   
 * By adding `isset($settings['block']) ? $settings['block'] : ''`, we can ensure
   that the `$block` variable is set to an empty string if the `block` key is not
   defined in the `$settings` array. This will prevent the PHP warning from being
   triggered. I tested it and it works for me, but maybe review it as I am not a
   developer and maybe there is other solution for that.
    -  This topic was modified 1 year, 11 months ago by [Hoek](https://wordpress.org/support/users/hoeczek/).

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

 *  Plugin Author [freemp](https://wordpress.org/support/users/freemp/)
 * (@freemp)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/php-error-undefined-array-key-block/#post-17905140)
 * Thanks for notifying.
 * Weird because `block`, if not defined, should already have been initialized as
   an empty string in line 33.
 *     ```wp-block-code
       $settings['block'] = get_option( 'javascript_notifier_block' );if ( false === $settings['block'] )	$settings['block'] = '';
       ```
   
 *  Thread Starter [Hoek](https://wordpress.org/support/users/hoeczek/)
 * (@hoeczek)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/php-error-undefined-array-key-block/#post-17905986)
 * Yeah, I understand. I am just showing you my logs and how I solved it. I am not
   a developer or programmer so not sure if I can help more.
 *  Plugin Author [freemp](https://wordpress.org/support/users/freemp/)
 * (@freemp)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/php-error-undefined-array-key-block/#post-17914395)
 * Fixed. Thanks again.

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

The topic ‘Php error – Undefined array key “block”’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/javascript-notifier.svg)
 * [JavaScript Notifier](https://wordpress.org/plugins/javascript-notifier/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/javascript-notifier/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/javascript-notifier/)
 * [Active Topics](https://wordpress.org/support/plugin/javascript-notifier/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/javascript-notifier/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/javascript-notifier/reviews/)

## Tags

 * [php-error](https://wordpress.org/support/topic-tag/php-error/)

 * 3 replies
 * 2 participants
 * Last reply from: [freemp](https://wordpress.org/support/users/freemp/)
 * Last activity: [1 year, 10 months ago](https://wordpress.org/support/topic/php-error-undefined-array-key-block/#post-17914395)
 * Status: resolved