承接 withinboredom/nameof 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

withinboredom/nameof

最新稳定版本:v0.2.1

Composer 安装命令:

composer require withinboredom/nameof

包简介

Get the name of anything

README 文档

README

This is a library to get the name of a variable. Some example usages:

enum Foo {
    case Bar;
    case Baz;
}

$arr = [];
$arr[nameof(Foo::Bar)] = 1; // resolves to 'Bar'

For compact:

$var = 1;
$bar = 2;
echo (compact(nameof($var), nameof($bar))); // ['var' => 1, 'bar' => 2]

Why?

This is useful when you want to use the name of a variable in a string, but want to retain easier refactoring. For example, normally when using compact you end up with a 'magic string' that references a variable name. However, this can be a problem if you want to refactor the variable name, as you have to change the string as well. This library allows you to use the nameof function to get the name of the variable, and then use that in the compact function. You can also use this for enum keys, and other places where you want to use the name of a variable.

Installation

composer require withinboredom/nameof

Example output

Here are some examples and their output, note that no error will be thrown if you pass it weird things because it isn't doing any parsing to make sure you are only passing sensible things.

echo nameof(1); // 1
echo nameof($myCallback(...)); // myCallback
echo nameof($x->prop); // prop
echo nameof($x->prop->fun(...)) // fun

统计信息

  • 总下载量: 2.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固