我想知道为什么可以在使用 PHP Trait 的类中访问该 Trait 的私有属性和方法。
这是我的 PHP 特征BulkMessageMembers.php::
<?php
namespace App\Traits;
trait BulkMessageMembers
{
private string $endpoint;
private string $text;
private array $phone_numbers;
private string $server_response;
public bool $sms_status = false;
public int $user_id;
}
Run Code Online (Sandbox Code Playgroud)
我的 PHP 类(这只是代码的一部分。)SMSJsonBulkMessageService.php使用我的 Trait:
<?php
namespace App\Services;
use App\Interfaces\SMSGateway;
use App\Models\Balance;
use App\Models\Message;
use App\Models\MessageSetting;
use App\Models\UserMessageSetting;
use App\Traits\BulkMessageMembers;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Support\Collection;
class SMSJsonBulkMessageService implements SMSGateway
{
use BulkMessageMembers;
public function __construct(
private readonly UserMessageSetting $preference,
private readonly Collection …Run Code Online (Sandbox Code Playgroud)