Problem/Motivation
Deprecated function: mb_substr(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\commerce_paypal\CheckoutSdk::formatAddress() (line 464 of /home/mysite/public_html/modules/contrib/commerce_paypal/src/CheckoutSdk.php)
#0 /home/mysite/public_html/core/includes/bootstrap.inc(346): _drupal_error_handler_real()
#1 [internal function]: _drupal_error_handler()
#2 /home/mysite/public_html/modules/contrib/commerce_paypal/src/CheckoutSdk.php(464): mb_substr()
#3 /home/mysite/public_html/modules/contrib/commerce_paypal/src/CheckoutSdk.php(352): Drupal\commerce_paypal\CheckoutSdk::formatAddress()
#4 /home/mysite/public_html/modules/contrib/commerce_paypal/src/CheckoutSdk.php(133): Drupal\commerce_paypal\CheckoutSdk->prepareOrderRequest()
#5 /home/mysite/public_html/modules/contrib/commerce_paypal/src/Plugin/Commerce/PaymentGateway/Checkout.php(446): Drupal\commerce_paypal\CheckoutSdk->updateOrder()
#6 /home/mysite/public_html/modules/contrib/commerce/modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentProcess.php(179): Drupal\commerce_paypal\Plugin\Commerce\PaymentGateway\Checkout->createPayment()
#7 /home/mysite/public_html/modules/contrib/commerce/modules/checkout/src/Plugin/Commerce/CheckoutFlow/CheckoutFlowWithPanesBase.php(546): Drupal\commerce_payment\Plugin\Commerce\CheckoutPane\PaymentProcess->buildPaneForm()
#8 [internal function]: Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowWithPanesBase->buildForm()
#9 /home/mysite/public_html/core/lib/Drupal/Core/Form/FormBuilder.php(531): call_user_func_array()
#10 /home/mysite/public_html/core/lib/Drupal/Core/Form/FormBuilder.php(278): Drupal\Core\Form\FormBuilder->retrieveForm()
#11 /home/mysite/public_html/core/lib/Drupal/Core/Form/FormBuilder.php(219): Drupal\Core\Form\FormBuilder->buildForm()
#12 /home/mysite/public_html/modules/contrib/commerce/modules/checkout/src/Controller/CheckoutController.php(143): Drupal\Core\Form\FormBuilder->getForm()
#13 [internal function]: Drupal\commerce_checkout\Controller\CheckoutController->formPage()
#14 /home/mysite/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#15 /home/mysite/public_html/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#16 /home/mysite/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#17 /home/mysite/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#18 /home/mysite/public_html/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#19 /home/mysite/public_html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#20 /home/mysite/public_html/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#21 /home/mysite/public_html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#22 /home/mysite/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#23 /home/mysite/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#24 /home/mysite/public_html/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#25 /home/mysite/public_html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#26 /home/mysite/public_html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#27 /home/mysite/public_html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#28 /home/mysite/public_html/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle()
#29 /home/mysite/public_html/index.php(19): Drupal\Core\DrupalKernel->handle()
#30 {main}
Steps to reproduce
This error seems to be appearing during the checkout process as the location in dblog shows
/checkout/order number/payment
referrer is /checkout/order number/review
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | interdiff_3277096_3-7.txt | 1.74 KB | andregp |
| #8 | 3277096-7.patch | 1.05 KB | andregp |
| #3 | 3277096-3.patch | 2.89 KB | matheusmaciel |
Comments
Comment #2
matheusmaciel commentedI'll be working on this issue.
Comment #3
matheusmaciel commentedI worked on the CheckoutSdk.php file changing the mb_substr(): passing the first parameter as a string for those that were passing a null value. Waiting for the review.
Comment #4
Johnny Santos commentedGoing in for the review
Comment #5
99gs3 commentedThanks for the patch.
Test so far seems to have resolved the issue.
Comment #6
andregp commentedI talked with Johnny Santos and I'm doing a review here to help...
Comment #7
andregp commentedThe best thing here would be to check for each function being called inside the mb_substr() method to be sure if they can or not return NULL. In come cases the null coalescing operator (??) is not necessary. For example on the line 479
The first parameter will never be null because it is being concatenated with the string
' '.There are some functions tough that can return null, such as label() (inside
'brand_name' => mb_substr($order->getStore()->label(), 0, 127),at line 371) because the documentation of label() says "@return string|\Drupal\Core\StringTranslation\TranslatableMarkup|nullThe label of the entity, or NULL if there is no label defined."
Some functions inside the mb_substr() are not from this module, so we need to check the documentation outside. I did this and the other functions I found that may return null are getLocality() (the one responsible for the error in the IS) and getPostalCode() at lines 464 and 466 as their documentation declares
@return mixed(which can include null).Comment #8
andregp commentedI reverted some changes to keep null coalescing operator only where the functions could return a null value as the first param of mb_substr().
Comment #9
elberComment #10
elberHi I revised the patch and it's good for me.
The issue's scope was resolved, and the coalescing operator sintaxe was wrote correctly.
This doc has a lot informations about coalescing operator (https://www.php.net/manual/pt_BR/migration70.new-features.php)
Comment #12
jsacksick commentedCommitted.