我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何在PHP中将对象数组定义为参数?

I want to something like this:

function __construct (string $todo, array[Tag] $tags) {}

That array[Tag] caused me a problem with error along the line: Unexpected '['

The main idea is to have strict type checking for an array of an object with Tag class.

How can I achieve this? And is it necessary for PHP's best practice?

Short answer, you can't. There is some hacky solution if you really need it though.

近期文章

  • Phpmailer和联系表格,成功消息,但没有结果
  • 解析基于字符串搜索和重构的字符串
  • PHP使用由第三方服务器/ URL设置的会话cookie ID
  • Angular 2无法加载预检的响应无效(重定向)[重复]
  • PDO获取输出bool(false)
  • file_get_contents(includes_url('/ js / jquery / jquery.js')); 不工作
  • 处理具有相同错误号的Mysql错误
  • Yii2使用curl通过WordPress登录
  • Wordpress - 获取以下用户的用户列表
  • WooCommerce - 获取产品子类别
  • 如何在不上传服务器的情况下直接将视频上传到Vimeo?
  • $这可以如何引用yii2中布局文件中的yii \ web \ View类的实例?
  • 使DataTable的每一行成为ID的超链接
  • 如果我尝试设置凭据,使用exec运行PowerShell脚本会挂起
  • mpdf在woocommerce我的帐户
  • 令牌未在mysql db中更新
  • 在vscode中配置php文件
  • 自动完成无法处理JSON文件
  • 如果使用电子邮件地址进行验证
  • 从对象的数组中调用每个值

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华