Skip to content
Merged
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
12 changes: 6 additions & 6 deletions src/Illuminate/Broadcasting/BroadcastEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,27 @@ protected function formatProperty($value)
* Get the channels for the given connection.
*
* @param array $channels
* @param string $connection
* @param string|null $connection
* @return array
*/
protected function getConnectionChannels($channels, $connection)
{
return is_array($channels[$connection] ?? null)
? $channels[$connection]
return is_array($channels[$connection ?? ''] ?? null)
? $channels[$connection ?? '']
Comment on lines +149 to +150
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the problem something else here?

Suggested change
return is_array($channels[$connection ?? ''] ?? null)
? $channels[$connection ?? '']
return (array_key_exists($connection, $channels) && is_array($connectionChannels = $channels[$connection]))
? $connectionChannels

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we can't pass null to any function that takes array index:

<?php

$arr =[];
var_dump(array_key_exists(null, $arr));

// Deprecated: Using null as the key parameter for array_key_exists() is deprecated, use an empty string instead in /in/KYhLO on line 4
// bool(false)

We'd have to use null-safe operator here too

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that wasn't my point. I added a suggestion for the original code. A suggestion with your changes incorporated would look like this:

Suggested change
return is_array($channels[$connection ?? ''] ?? null)
? $channels[$connection ?? '']
return ($connection !== null && array_key_exists($connection, $channels) && is_array($connectionChannels = $channels[$connection]))
? $connectionChannels

: $channels;
}

/**
* Get the payload for the given connection.
*
* @param array $payload
* @param string $connection
* @param string|null $connection
* @return array
*/
protected function getConnectionPayload($payload, $connection)
{
$connectionPayload = is_array($payload[$connection] ?? null)
? $payload[$connection]
$connectionPayload = is_array($payload[$connection ?? ''] ?? null)
? $payload[$connection ?? '']
: $payload;

if (isset($payload['socket'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Relations/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public function match(array $models, EloquentCollection $results, $relation)
foreach ($models as $model) {
$attribute = $this->getDictionaryKey($this->getForeignKeyFrom($model));

if (isset($dictionary[$attribute])) {
$model->setRelation($relation, $dictionary[$attribute]);
if (isset($dictionary[$attribute ?? ''])) {
$model->setRelation($relation, $dictionary[$attribute ?? '']);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Worker
/**
* The name of the worker.
*
* @var string
* @var string|null
*/
protected $name;

Expand Down Expand Up @@ -363,8 +363,8 @@ protected function getNextJob($connection, $queue)
$this->raiseBeforeJobPopEvent($connection->getConnectionName());

try {
if (isset(static::$popCallbacks[$this->name])) {
if (! is_null($job = (static::$popCallbacks[$this->name])($popJobCallback, $queue))) {
if (isset(static::$popCallbacks[$this->name ?? ''])) {
if (! is_null($job = (static::$popCallbacks[$this->name ?? ''])($popJobCallback, $queue))) {
$this->raiseAfterJobPopEvent($connection->getConnectionName(), $job);
}

Expand Down