Website maintenance
Sign: Dead end - no way to turn around - Possibly an unexpected end as in the case of Wordpress.

PHP error "unexpected end of file

With many a WordPress project, you find yourself in the situation of designing your own templates. WordPress templates are typical representatives of the old PHP school, according to which PHP is already its own template engine and thus form a hybrid of HTML and PHP instructions. This is more or less how PHP came into being. In the meantime, PHP and HTML code are separated by additional template engines such as the oldie but goldie Smarty or Twig and Blade (Laravel), which makes sense for larger projects, especially for reasons of reusability, but also clarity of the project. Nevertheless, WordPress does without template engines and leaves the separation of logic and presentation to the developer. The result is, for example, code expressions of the form:

"Unfortunately", however, the short version usually also works by replacing <?php with <?

Many Apache web servers will execute the code at this point. This is because in PHP.ini the configuration variable "short_open_tag" the value "On", which allows the execution of this syntax. However, it becomes problematic if the PHP version has the value "Off". At this point there will be a fatal error, e.g:

"PHP Parse error: syntax error, unexpected end of file in ..."

The problem with this is that many development environments, such as "MAMP", allow the short spelling by default. This can lead to nasty surprises on the hoster's production server - and anyone who often works with WordPress knows that debugging is not necessarily one of the strengths of this CMS.

Developers who use PHPStorm, for example, can tick the "Short Open Tag Usage" option under Inspections > PHP > Code Style and then receive a corresponding warning during development:

Happy WordPress Coding!

One more hint: Most likely you will not see the error message on the screen, but instead simply a white screen of death will be displayed. However, you will find such a message somewhere in the error logs of your hoster. Pay attention to the PHP files that you have modified or created.

 

See also

More techdoks and snippets

Shortcode E-Mail Obfuscator

The following shortcode snippet is useful for disguising emails to protect them from SPAM. Please note that this method only works if Javascript is activated. In addition, there is no 100%igen protection against bots,...

Elementor popup / flyout menu no longer closes for mobile view

Elementor: Version 3.72 Behaviour: An Elementor popup opens, but no longer closes (when clicking on icon or Esc or other triggers). If you look in the source code, you will find the Javascript error message: "Elementor t.entrance_animation_duration is undefined" Cause:...

PHPStorm: Local Changelist in Git Tool disappeared

Problem: Local Change List under PHPStorm is missing in the Git Tool Solution: From time to time I had the phenomenon that the Local Changelist (the files in my version control) were not visible as tabs in the Git tool....

Variable not available in blade component

Problem: The parameter transfer of a blade attribute does not work, the variable in the component is empty. There is no error message, but the variable does not appear to have been passed. Solution: The error may lie in the usage...

WP CLI Error: Error establishing a database connection.

Appearance: Submitting commands via WP CLI, but WordPress in the browser works. This error often occurs when the WP CL interpreter cannot correctly interpret the database connection in wp-config.php. Solution: In 99% of all cases the...

Convert Px to SEM / EM very quickly with Alfred

There is a wonderful Alfred workflow on the Mac that converts Px to Rem: Download direct link: https://raw.githubusercontent.com/vitorgalvao/requested-alfred-workflows/master/Workflows/PxRemEm.alfredworkflow Simply install, then type CMD-Space: Alfred Bar "pxrem" and enter the number in pixels. The conversion to REM will...

Setting up XDebug with PHPStorm and Valet Development Environment

Preparation: Homebrew should be installed Valet should be installed and running: https://laravel.com/docs/7.x/valet Browser extension for PHPSTORM should be installed: https://www.jetbrains.com/help/phpstorm/browser-debugging-extensions.html gerry@webgarten ~ % brew install pecl gerry@webgarten ~ % pecl install xdebug In case of error message: Warning:...