Problem/Motivation

The site logs show a PHP 8.1 deprecation warning when exporting references to the MARC format.

Steps to reproduce

1. Install Drupal 10 with PHP 8.1+
2. Install and configure bibcite
3. Create a reference
4. Export the reference to MARC format
5. Check the logs: Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in PhpMarc\Field->__construct()

Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in PhpMarc\Field->__construct() (line 128 of /home/site/wwwroot/vendor/caseyamcl/php-marc21/lib/PhpMarc/Field.php) #0 /home/site/wwwroot/web/core/includes/bootstrap.inc(166): _drupal_error_handler_real(8192, 'preg_match(): P...', '/home/site/wwwr...', 128)
#1 [internal function]: _drupal_error_handler(8192, 'preg_match(): P...', '/home/site/wwwr...', 128)
#2 /home/site/wwwroot/vendor/caseyamcl/php-marc21/lib/PhpMarc/Field.php(128): preg_match('/^[0-9A-Za-z]{3...', NULL)
#3 /home/site/wwwroot/web/modules/contrib/bibcite/modules/bibcite_marc/src/Encoder/MarcEncoder.php(304): PhpMarc\Field->__construct()
#4 /home/site/wwwroot/web/modules/contrib/bibcite/modules/bibcite_marc/src/Encoder/MarcEncoder.php(286): Drupal\bibcite_marc\Encoder\MarcEncoder->buildEntry(Array)
#5 [internal function]: Drupal\bibcite_marc\Encoder\MarcEncoder->Drupal\bibcite_marc\Encoder\{closure}(Array)
#6 /home/site/wwwroot/web/modules/contrib/bibcite/modules/bibcite_marc/src/Encoder/MarcEncoder.php(285): array_map(Object(Closure), Array)
#7 /home/site/wwwroot/vendor/symfony/serializer/Encoder/ChainEncoder.php(43): Drupal\bibcite_marc\Encoder\MarcEncoder->encode(Array, 'marc', Array)
#8 /home/site/wwwroot/vendor/symfony/serializer/Serializer.php(418): Symfony\Component\Serializer\Encoder\ChainEncoder->encode(Array, 'marc', Array)
#9 /home/site/wwwroot/vendor/symfony/serializer/Serializer.php(143): Symfony\Component\Serializer\Serializer->encode(Array, 'marc', Array)
#10 /home/site/wwwroot/web/modules/contrib/bibcite/modules/bibcite_export/src/Controller/ExportController.php(75): Symfony\Component\Serializer\Serializer->serialize(Array, 'marc')
#11 /home/site/wwwroot/web/modules/contrib/bibcite/modules/bibcite_export/src/Controller/ExportController.php(113): Drupal\bibcite_export\Controller\ExportController->processExport(Array, Object(Drupal\bibcite\Plugin\BibciteFormat), 'bibcite_referen...')
#12 [internal function]: Drupal\bibcite_export\Controller\ExportController->export(Object(Drupal\bibcite\Plugin\BibciteFormat), 'bibcite_referen...', Object(Drupal\bibcite_entity\Entity\Reference))
#13 /home/site/wwwroot/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#14 /home/site/wwwroot/web/core/lib/Drupal/Core/Render/Renderer.php(637): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /home/site/wwwroot/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#16 /home/site/wwwroot/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#17 /home/site/wwwroot/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /home/site/wwwroot/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#19 /home/site/wwwroot/web/modules/contrib/simple_oauth/src/HttpMiddleware/BasicAuthSwap.php(68): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /home/site/wwwroot/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /home/site/wwwroot/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /home/site/wwwroot/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /home/site/wwwroot/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(201): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /home/site/wwwroot/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(138): Drupal\page_cache\StackMiddleware\PageCache->fetch(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /home/site/wwwroot/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(87): Drupal\page_cache\StackMiddleware\PageCache->lookup(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /home/site/wwwroot/web/modules/contrib/shield/src/ShieldMiddleware.php(263): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /home/site/wwwroot/web/modules/contrib/shield/src/ShieldMiddleware.php(130): Drupal\shield\ShieldMiddleware->bypass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /home/site/wwwroot/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\shield\ShieldMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /home/site/wwwroot/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /home/site/wwwroot/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /home/site/wwwroot/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /home/site/wwwroot/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /home/site/wwwroot/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#34 {main}.

Proposed resolution

The bibcite/composer.json requires caseyamcl/php-marc21: "~1.0". This version is not compatible with PHP 8.1. This constraint should be updated to a modern version, such as ^3.0, which supports PHP 8.1. This will require updating the composer.lock file as well.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Issue fork bibcite-3558187

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kieran.cott created an issue. See original summary.

mark_fullmer’s picture

Assigned: Unassigned » mark_fullmer
mark_fullmer’s picture

Status: Active » Needs work

The proposed resolution indicates incrementing the version of caseyamcl/php-marc21 from ^1.0 to ^3.0, but there is no 3.x branch or related tags in https://github.com/caseyamcl/php-marc21/releases

This is also evident as shown in the failing automated tests.

Would the original poster be able to clarify the intent here? Certainly the underlying deprecated syntax should be fixed, but since the library does not appear to have been updated in ~5 years, potentially the best option here would be to embrace patching (using cweagans/composer-patches)?

mark_fullmer’s picture

Title: Deprecated function: preg_match() passing null in PhpMarc\Field due to outdated caseyamcl/php-marc21 dependency » [PHP 8.1] Deprecated function: preg_match() passing null in PhpMarc\Field due to outdated caseyamcl/php-marc21 dependency
dasginganinja’s picture

I emailed Casey today with a PHP 8.4 fix and asked him to release a PHP 8.4 compatible version. Hopefully something comes of that!

dasginganinja’s picture

Good news everyone: There is now a 2.0 branch which can be targeted / tested now.

https://github.com/caseyamcl/php-marc21/releases/tag/v2.0

Thanks Casey!

mark_fullmer’s picture

Version: 3.0.0-beta3 » 3.0.x-dev
Status: Needs work » Needs review

Good news everyone: There is now a 2.0 branch which can be targeted / tested now.

That is indeed great news! I've updated the MR to reflect the new target branch version. Tests are passing. If I can ask for a human review, we can get this updated!

mark_fullmer’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.