没有不值得去解决的问题,也没有不值得去学习的技术!

在 phpstorm 中提示:@property-read

在 phpstorm 中提示:@property-read

1、在 phpstorm 中提示:@property-read 。如图1

在 phpstorm 中提示:@property-read
图1
Plaintext

$setting = ConventionEmailSetting::findSettingByConventionId($params['convention_id']);
if($setting && $setting->enable_custom_server == ConventionEmailSetting::ENABLE_CUSTOM_SERVER_YES){
	Yii::$app->mailer->transport = [
		'class' => 'Swift_SmtpTransport',
		'host' => $setting->host,
		'username' => $setting->username,
		'password' => $setting->password,
		'port' => $setting->port ?: '25',
		'encryption' => $setting->encryption ?: 'tls',
	];
}

2、在 common/config/main-local.php 中

PHP

 [
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtpdm.aliyun.com',
                'username' => '',
                'password' => '',
                'port' => '25',
                'encryption' => 'tls',
            ]
        ],
    ],
];


3、在 Yii2 中,yii\swiftmailer\Mailer 组件中对 transport 并不是通过公开属性设置的,而是通过 setTransport() 方法设置的。而 Yii::$app->mailer->transport = […] 属于 直接设置属性方式,PHPStorm 无法静态分析出你其实是通过 magic setter 间接调用了 setter 方法。这就是它提示 @property-read $transport 的原因。调整如下,不再报错。如图2

在 Yii2 中,yii\swiftmailer\Mailer  组件中对 transport 并不是通过公开属性设置的,而是通过 setTransport() 方法设置的。而 Yii::$app->mailer->transport = [...] 属于 直接设置属性方式,PHPStorm 无法静态分析出你其实是通过 magic setter 间接调用了 setter 方法。这就是它提示 @property-read $transport 的原因。调整如下,不再报错
图2
PHP

Yii::$app->mailer->setTransport([
	'class' => 'Swift_SmtpTransport',
	'host' => $setting->host,
	'username' => $setting->username,
	'password' => $setting->password,
	'port' => $setting->port ?: '25',
	'encryption' => $setting->encryption ?: 'tls',
]);

PHP / Laravel / Yii2 老项目维护与长期技术支持

如果你的 PHP / Laravel / Yii2 项目已经上线,但遇到原开发离职、Bug 长期无人修复、接口不稳定、性能下降、代码难以接手等问题,可以联系我做一次远程技术排查。

适合以下情况:
✅ 老旧 PHP 系统无人维护
✅ Laravel / Yii2 项目 Bug 修复
✅ 后台管理系统小功能迭代
✅ RESTful API 接口排查
✅ MySQL / Redis / Nginx 性能问题
✅ 长期远程兼职维护

可先从一次小问题开始:
✅ 线上报错排查
✅ 接口异常分析
✅ 慢查询与性能瓶颈定位
✅ 代码结构初步评估
✅ 部署环境与日志检查

如需咨询,请联系我,并注明:PHP 维护咨询

联系方式:
Telegram:@shuijingwan
微信:13980074657
邮箱:shuijingwanwq@gmail.com