Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 这种写法的人当时是不是吸毒了才这么写

这种写法的人当时是不是吸毒了才这么写

Jun 23, 2016 pm 01:33 PM

感觉是一种的抽风的写法,也可能是吸毒了太兴粪的写法,不知为了啥。很多人就是不喜欢用常规出牌,总是在那里搞手银的事,这样能升华到那个境界吗


回复讨论(解决方案)

原生的shopnc好像不是这样写的,可能是后来加上吧。

很正常,后补的锁

很正常,后补的锁


此锁何义?

意义在于你不执行它的一段隐藏代码(用于那个常量的定义以其他)就无法让程序执行

意义在于你不执行它的一段隐藏代码(用于那个常量的定义以其他)就无法让程序执行


从原理上说不通

理论上程序都是写好的,才发布。
我觉得没必要加上那么一段代码,又不是用户会随意访问代码,改变代码流程,我觉得完全没必要做这个判断。

理论上程序都是写好的,才发布。
我觉得没必要加上那么一段代码,又不是用户会随意访问代码,改变代码流程,我觉得完全没必要做这个判断。


这里不是有没有必要的问题,而是语法错语的问题,当然这是我目前理解,也是发这帖的原因,都语法错误了,还谈啥?
当然也可能没有错误,不过PHP手册上说的这个return的用法是在函数中,而这里的return没有用在函数中,所以错误!
我希望大家谈谈这个,而不是啥这里这么玩必不必要,再重申一遍, 这里是不是语法错误!!!!!!!!!!!!!!!!

这种写法主要是用于配置文件,  在外面可以这样写  $redisConfig = include('config.inc.php‘);  外面可以接收return的值

第一行是控制入口, 避免外部直接访问该文件  

<?phpdefined('InShopNC') or exit('Access Invalid!');return $config;
Copy after login

怎么会是语法错呢?

defined('InShopNC') or exit('Access Invalid!');
是说,如果常量 InShopNC 没有定义,就退出程序并显示 Access Invalid!
否则 返回变量 $config

显然这个程序不能被直接访问,不然只会输出 Access Invalid!
只有在定义了常量 InShopNC 的程序链用 $x = include('config/config.ini.php'); 才能获取到已经定义过的变量 $config 的值

通常 config.ini.php 是用来定义系统初值的地方,而作者却没有这样做,显然是出于某种原因在别处定义了。zy205817 不也说 原生的shopnc好像不是这样写的 吗?
所以我说是:后补的锁

php 中的 return 可以放在任何地方,如果在函数或方法中就是结束当前函数或方法并返回值
如果在函数或方法外,就是结束当前程序文件并返回值

如果你的教科书中没有提及这一点,那么请将此书丢进茅厕里(茅厕还嫌他臭)

手册中明确的说到
如果在一个函数中调用 return 语句,将立即结束此函数的执行并将它的参数作为函数的值返回。 return 也会终止 eval() 语句或者脚本文件的执行。
下面还有很多,我不一一复制了,自己去看

return语句的妙用还真不少

defined('InShopNC') or exit('Access Invalid!');
return $config;
就是有定义过InShopNC的时候,才可以访问 $config;

如果没定义过, 后面or exit('Access Invalid!'); 就已经退出了,不会执行 return $config

所以这个文件如果直接访问是会显示Access Invalid的。
必须是由其他已经定义了InShopNc的页面才可以调用。

defined('InShopNC') or exit('Access Invalid!');
Copy after login


学习了 这也是一种文件权限的妙用

http://php.net/manual/zh/function.return.php

http://php.net/manual/zh/function.return.php


手册里面写了,如果是include 就返回,有什么问题,为什么会有语法错误?
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

See all articles