PHP use
一个普通的php 文件 也有命名空间 php 类文件 有用命名空间 ,在PHP 普通文件中 已经use了PHP类文件,当在PHP普通文件中 调用 类文件的方法时 为什么还需要include 类文件呢
回复内容:
一个普通的php 文件 也有命名空间 php 类文件 有用命名空间 ,在PHP 普通文件中 已经use了PHP类文件,当在PHP普通文件中 调用 类文件的方法时 为什么还需要include 类文件呢
use
只是用于减少在namespace
系统中过长类名的表示,并不含有自动加载对应类源码的作用。类的源码仍然需要使用include
进行加载。当然,目前也有很多根据namesapce
系统来完成类加载的自动加载器,只要在php
中注册这些类加载器,可以完成根据namesapce
识别路径以及对类的自动加载,这类加载器的典型代表就是符合PSR-0
或PSR-4
的类加载器。
同意楼上。现在可以用composer来生成一个类的自动加载器,这样在A类中使用B类时只需要按照命名空间use就行,关于composer的自动加载原理可以看看我的这篇文章,希望有帮助,Laravel学习笔记之Composer自动加载

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

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,
