定制 sspat/reserved-words 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

sspat/reserved-words

Composer 安装命令:

composer require sspat/reserved-words

包简介

Validates strings against reserved words of a specific php version

README 文档

README

Latest Version Build Mutation testing badge Test Coverage Type Coverage License

About

This package allows checking strings for being a PHP reserved word and also the possibility of using the string as a PHP namespace/class/interface/trait, function, method or constant name.

By default checks are performed for your current runtime PHP version, but you can specify any version to check against.

This can come in handy during code generation for example, when PHP code is generated based on some user input.

Reserved words in the PHP documentation:

Installation

composer require sspat/reserved-words

Usage

<?php

use sspat\ReservedWords\ReservedWords;

$reservedWords = new ReservedWords();
$word = 'list';

/**
 * Checks that the word is reserved in any PHP version.
 * It is still possible to use reserved words in php code in many places, but generally you should avoid it.
 * This method also returns true for words that are marked as "soft" reserved in the PHP docs and may
 * become reserved in future versions of the language.
 */
$isReserved = $reservedWords->isReserved($word);
/**
 * Checks that the word cannot be used as a constant name in your current php version.
 */
$cannotUseAsConstantName = $reservedWords->isReservedConstantName($word);
/**
 * Checks that the word cannot be used as a namespace part in your current php version.
 * 
 * This is used for checking parts of namespaces, not full namespace strings.
 * E.g. calling this with `Some\Namespace\String` is incorrect, you should make three separate calls
 * with `Some`, `Namespace` and `String`.
 */
$cannotUseAsNamespaceName = $reservedWords->isReservedNamespaceName($word);
/**
 * Checks that the word cannot be used as a class/interface/trait name in your current php version.
 */
$cannotUseAsNamespaceName = $reservedWords->isReservedClassName($word);
/**
 * Checks that the word cannot be used as a function name in your current php version.
 */
$cannotUseAsFunctionName = $reservedWords->isReservedFunctionName($word);
/**
 * Checks that the word cannot be used as a method name in your current php version.
 */
$cannotUseAsMethodName = $reservedWords->isReservedMethodName($word);

/**
 * The following methods also accept a second parameter, to check against a PHP version different than your current runtime
 */
$cannotUseAsConstantName = $reservedWords->isReservedConstantName($word, '5.6');
$cannotUseAsNamespaceName = $reservedWords->isReservedNamespaceName($word, '5.6.1');
$cannotUseAsNamespaceName = $reservedWords->isReservedClassName($word, '5.6.1');
$cannotUseAsFunctionName = $reservedWords->isReservedFunctionName($word, '8.0');
$cannotUseAsMethodName = $reservedWords->isReservedMethodName($word, '7.4.2');

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固