Skip to content

Fixes to launch Magento with PHP 8.1 #34506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct(
*
* @return array
*/
#[\ReturnTypeWillChange]
public function current()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to specify a proper return type for this method instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fascinosum , in PHP >= 8 the return type for this method is mixed (https://www.php.net/manual/en/class.iteratoriterator.php) , but in PHP 7.4 this return type is not specified yet.

{
$current = parent::current();
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Analytics/ReportXml/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function getConfig()
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
*/
#[\ReturnTypeWillChange]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to specify a proper return type for this method instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fascinosum , in PHP >= 8 the return type for this method is mixed (https://www.php.net/manual/en/jsonserializable.jsonserialize.php) , but in PHP 7.4 this return type is not specified yet.

public function jsonSerialize()
{
return [
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Backend/App/DefaultPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class DefaultPath implements \Magento\Framework\App\DefaultPathInterface
*/
public function __construct(\Magento\Backend\App\ConfigInterface $config)
{
$pathParts = explode('/', $config->getValue('web/default/admin'));
$path = $config->getValue('web/default/admin');
$pathParts = $path ? explode('/', $path) : [''];

$this->_parts = [
'area' => isset($pathParts[0]) ? $pathParts[0] : '',
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Backend/Model/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ protected function _findParentItems($menu, $itemId, &$parents)
*
* @return string
*/
#[\ReturnTypeWillChange]
public function serialize()
{
return $this->serializer->serialize($this->toArray());
Expand Down Expand Up @@ -294,7 +295,7 @@ public function toArray()
* @return void
* @since 100.2.0
*/
public function unserialize($serialized)
public function unserialize($serialized): void
{
$data = $this->serializer->unserialize($serialized);
$this->populateFromArray($data);
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Backend/Model/Menu/Filter/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct(\Iterator $iterator)
*
* @return bool true if the current element is acceptable, otherwise false.
*/
#[\ReturnTypeWillChange]
public function accept()
{
return !($this->current()->isDisabled() || !$this->current()->isAllowed());
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Model/Menu/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Iterator extends \ArrayIterator
*
* @return void
*/
public function rewind()
public function rewind(): void
{
$this->ksort();
parent::rewind();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use Magento\Framework\View\Helper\SecureHtmlRenderer;
<?php foreach ($tabs as $_tab): ?>
<?php $tabId = $block->getTabId($_tab) ?>
<?php $_tabClass = 'tab-item-link ' . $block->getTabClass($_tab) . ' ' .
(preg_match('/\s?ajax\s?/', $_tab->getClass()) ? 'notloaded' : '') ?>
(preg_match('/\s?ajax\s?/', $_tab->getClass() ?? '') ? 'notloaded' : '') ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be fixed in \Magento\Backend\Block\Widget\Tabs::getTabClass intead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fascinosum the problem is in a method 'getClass', and $_tab can be a DataObject

<?php $_tabType = (!preg_match('/\s?ajax\s?/', $_tabClass) && $block->getTabUrl($_tab) != '#') ? 'link' : '' ?>
<?php $_tabHref = $block->getTabUrl($_tab) == '#' ?
'#' . $tabId . '_content' :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ProductLimitation implements \ArrayAccess
* @return bool
* @since 101.0.0
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return array_key_exists($offset, $this->productLimitationFilters);
Expand All @@ -45,6 +46,7 @@ public function offsetExists($offset)
* @return mixed
* @since 101.0.0
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->productLimitationFilters[$offset];
Expand All @@ -56,6 +58,7 @@ public function offsetGet($offset)
* @return void
* @since 101.0.0
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
$this->productLimitationFilters[$offset] = $value;
Expand All @@ -66,6 +69,7 @@ public function offsetSet($offset, $value)
* @return void
* @since 101.0.0
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
unset($this->productLimitationFilters[$offset]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function setElements(array $elements, $scope)
*
* @return \Magento\Config\Model\Config\StructureElementInterface
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->_flyweight;
Expand All @@ -79,6 +80,7 @@ public function current()
*
* @return void Any returned value is ignored.
*/
#[\ReturnTypeWillChange]
public function next()
{
next($this->_elements);
Expand Down Expand Up @@ -106,6 +108,7 @@ protected function _initFlyweight(array $element)
*
* @return void
*/
#[\ReturnTypeWillChange]
public function key()
{
key($this->_elements);
Expand All @@ -117,6 +120,7 @@ public function key()
* @return bool The return value will be casted to boolean and then evaluated.
* Returns true on success or false on failure.
*/
#[\ReturnTypeWillChange]
public function valid()
{
return (bool)current($this->_elements);
Expand All @@ -127,6 +131,7 @@ public function valid()
*
* @return void Any returned value is ignored.
*/
#[\ReturnTypeWillChange]
public function rewind()
{
reset($this->_elements);
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Customer/Model/Indexer/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function addFieldToFilter($attribute, $condition = null)
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function count()
{
return $this->customerCollection->getSize();
Expand All @@ -92,6 +93,7 @@ public function count()
*
* @return Traversable
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
$this->customerCollection->setPageSize($this->batchSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function __construct(
*
* @return array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
if ($this->options === null) {
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Eav/Model/Entity/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function getValueTablePrefix()
*/
public function getEntityTablePrefix()
{
$tablePrefix = trim($this->_data['value_table_prefix']);
$tablePrefix = trim((string) $this->_data['value_table_prefix']);

if (empty($tablePrefix)) {
$tablePrefix = $this->getEntityTable();
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/ImportExport/Model/Import/AbstractSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function getColNames()
*
* @return array
*/
#[\ReturnTypeWillChange]
public function current()
{
$row = $this->_row;
Expand All @@ -101,6 +102,7 @@ public function current()
*
* @return void
*/
#[\ReturnTypeWillChange]
public function next()
{
$this->_key++;
Expand All @@ -127,6 +129,7 @@ abstract protected function _getNextRow();
*
* @return int -1 if out of bounds, 0 or more otherwise
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->_key;
Expand All @@ -137,6 +140,7 @@ public function key()
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function valid()
{
return -1 !== $this->_key;
Expand All @@ -147,6 +151,7 @@ public function valid()
*
* @return void
*/
#[\ReturnTypeWillChange]
public function rewind()
{
$this->_key = -1;
Expand All @@ -161,6 +166,7 @@ public function rewind()
* @return void
* @throws \OutOfBoundsException
*/
#[\ReturnTypeWillChange]
public function seek($position)
{
if ($position == $this->_key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected function _construct()
*
* @return \Iterator
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
$connection = $this->getConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function execute(Observer $observer)
/** @var \Magento\User\Model\User $user */
$user->loadByUsername($username);

if ($user->getId() && $this->userExpirationManager->isUserExpired($user->getId())) {
if ($user->getId() && $this->userExpirationManager->isUserExpired((string) $user->getId())) {
$this->userExpirationManager->deactivateExpiredUsersById([$user->getId()]);
throw new AuthenticationException(
__(
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Shipping/Model/Simplexml/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Element extends \Magento\Framework\Simplexml\Element
* @param string $namespace If specified, the namespace to which the attribute belongs.
* @return void
*/
public function addAttribute($name, $value = null, $namespace = null)
public function addAttribute($name, $value = null, $namespace = null): void
{
$value = $value !== null ? $this->xmlentities($value) : '';
parent::addAttribute($name, $value, $namespace);
Expand All @@ -34,7 +34,7 @@ public function addAttribute($name, $value = null, $namespace = null)
* @param string $namespace If specified, the namespace to which the child element belongs.
* @return \Magento\Shipping\Model\Simplexml\Element
*/
public function addChild($name, $value = null, $namespace = null)
public function addChild($name, $value = null, $namespace = null): self
{
if ($value !== null) {
$value = $this->xmlentities($value);
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Ui/DataProvider/AbstractDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public function getData()
*
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
{
return $this->getCollection()->count();
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Ui/Model/Export/SearchResultIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct(
/**
* @return array|mixed
*/
#[\ReturnTypeWillChange]
public function current()
{
return current($this->items);
Expand All @@ -32,6 +33,7 @@ public function current()
/**
* @return int|mixed
*/
#[\ReturnTypeWillChange]
public function key()
{
return key($this->items);
Expand All @@ -40,6 +42,7 @@ public function key()
/**
* @return void
*/
#[\ReturnTypeWillChange]
public function next()
{
next($this->items);
Expand All @@ -48,6 +51,7 @@ public function next()
/**
* @return void
*/
#[\ReturnTypeWillChange]
public function rewind()
{
reset($this->items);
Expand All @@ -56,6 +60,7 @@ public function rewind()
/**
* @return bool
*/
#[\ReturnTypeWillChange]
public function valid()
{
return $this->key() !== null;
Expand Down
1 change: 1 addition & 0 deletions lib/internal/Magento/Framework/Api/Search/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function setCustomAttributes(array $attributes)
* @return \ArrayIterator
* @since 100.1.0
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
$attributes = (array)$this->getCustomAttributes();
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/Magento/Framework/App/Cache/Frontend/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ protected function _getCacheSettings()
*
* @return \Magento\Framework\Cache\FrontendInterface
*/
#[\ReturnTypeWillChange]
public function current()
{
$this->_initialize();
Expand All @@ -106,6 +107,7 @@ public function current()
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function key()
{
$this->_initialize();
Expand All @@ -115,6 +117,7 @@ public function key()
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function next()
{
$this->_initialize();
Expand All @@ -124,6 +127,7 @@ public function next()
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function rewind()
{
$this->_initialize();
Expand All @@ -133,6 +137,7 @@ public function rewind()
/**
* @inheritdoc
*/
#[\ReturnTypeWillChange]
public function valid()
{
$this->_initialize();
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/Magento/Framework/App/RouterList.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected function getRouterInstance($routerId)
* @link http://php.net/manual/en/iterator.current.php
* @return RouterInterface
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->getRouterInstance($this->key());
Expand All @@ -71,6 +72,7 @@ public function current()
* @link http://php.net/manual/en/iterator.next.php
* @return void Any returned value is ignored.
*/
#[\ReturnTypeWillChange]
public function next()
{
next($this->routerList);
Expand All @@ -82,6 +84,7 @@ public function next()
* @link http://php.net/manual/en/iterator.key.php
* @return string|int|null
*/
#[\ReturnTypeWillChange]
public function key()
{
return key($this->routerList);
Expand All @@ -94,6 +97,7 @@ public function key()
* @return boolean The return value will be casted to boolean and then evaluated.
* Returns true on success or false on failure.
*/
#[\ReturnTypeWillChange]
public function valid()
{
return !!current($this->routerList);
Expand All @@ -105,6 +109,7 @@ public function valid()
* @link http://php.net/manual/en/iterator.rewind.php
* @return void Any returned value is ignored.
*/
#[\ReturnTypeWillChange]
public function rewind()
{
reset($this->routerList);
Expand Down
Loading