Skip to main content

Troubleshooting PHP 8.3 mbstring issues on Ubuntu with Nginx

Maintaining a Drupal site is usually smooth sailing once the environment is properly set up. However, even in a stable environment, updates to modules can sometimes reveal underlying configuration issues that weren't apparent before. This was the case when I updated a contrib module on a Drupal 10.3 site, which suddenly started throwing errors related to the mbstring PHP extension.

 

brew changing PHP versions on OSX

Installing PHP on OSX and it installed PHP 8.2.x.  However, for my applications I need to run 8.1.x.  How do you switch the current PHP version?

 

Current version

Check the current PHP version by executing the command

php -v

Response:

Drupal 9 adding a reCAPTCHA element to a webform

 

JSON structure

Outlining the structure of the elements common attributes: type, title, name and required;

Text area

{
    "type": "webform_multiple",
    "title": "What's new?",
    "name": "what_s_new_",
    "required": false
}

Text field

An additional attribute for the text field is maxlength

How to get the node.nid from the alias

In this instance, I'll check the beginning of the string.  I want to focus on the href's that start with /node/.  Which has been added using the variable $catchPhrase.

Using the Drupal service path_alias to return the node.nid as follows:

How to remove .DS_Store from your git repo

Working from the bases that .DS_Store has not been added to your git repository, then you can add it to your .gitignore file.

touch .gitignore

In the .gitignore file add the following

# Hide the DS_Store files
**/.DS_Store

However, if it's already there, then in Terminal you will need to write:

PHP - sort a multidimensional array

To sort through a multidimensional array seems to be a function that I occasionally call on.  Handy to have referenced here:

VS Code - Unable to locate phpcs

phpcs issue in Visual Studio Code, I'm receiving this warning in VS Code:

phpcs: Unable to locate phpcs. Please add phpcs to your global path or use composer decency manager to install it in your project locally.

 

How to fix

You can install phpcs by using composer global command:

composer global require squizlabs/php_codesniffer

Then in VS Code, go to 

Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead

Oh the treasure of a client coming to you with a site they have removed the previous dev on... treasure hunt.  Not.

Anyway, gaining access to an old site, working through the errors I came across this deprecated code

Deprecated function: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in common_check_language() (line 306 of /path/to/file).

 

Subscribe to PHP