Comments (3)
首先感谢关注!
PHP 允许静态方法被动态调用,通过 isset($this)
可以判断当前方法是否处在类实例的上下文中。因此如果 isset($this)
为 TRUE,则可以使用 $this
,否则创建自身。印象中 Laravel 经常有这种语法糖。
您可以看一下单元测试,在几个常见 PHP 版本都是可以跑通过的。
https://coveralls.io/builds/21963969/source?filename=aop/AlipayRequestFactory.php#L95
from alipay-sdk-php.
测试了确实可以 类实例->静态方法 这样调用 涨知识
但是没有找到这方面的知识点 请问有相关文档分享下吗 感谢
from alipay-sdk-php.
这是由于 PHP 的面向对象特性决定的。
根据 官方文档 的描述:
Declaring class properties or methods as static makes them accessible without needing an instantiation of the class.
使用 static
关键字并不是真正地将方法定义为「静态方法」,而是「makes them accessible without needing an instantiation of the class(使它们无需类实例也可被访问)」。你可测试以下代码:
class FooBar
{
public static function foo() {}
public function foo() {}
}
// Fatal error: Cannot redeclare FooBar::foo()
无论方法是否使用 static
,它们都是方法,不能重名。
另外,文档中有明确写道:
A property declared as static cannot be accessed with an instantiated class object (though a static method can).
静态方法可通过类实例访问,但静态属性不可以。
from alipay-sdk-php.
Related Issues (20)
- 支付宝的小程序模板开发,能支持不? HOT 1
- 官方升级到 3.3.2 了 HOT 2
- 为什么会有两个user_id:alipay_user_id,user_id?官方文档只有一个user_id。 HOT 7
- 如何获取三方登陆签名? HOT 5
- 创建$keyPair时,产生空的结果 HOT 3
- 这个SDK 只能用于小程序场景吗 HOT 1
- 项目描述没有同步修改为 3.3.2 HOT 1
- 能够把直付通的借口也添加上去? HOT 1
- 新接手的项目引入了作者的包,但是已经不维护了吗 HOT 3
- 支付宝密钥的问题 HOT 2
- 2.0 版本 request 里面没有 接口文件了吗? HOT 8
- biz_content根本没有组装给curl发送. HOT 3
- bizContent未加入到请求参数中 HOT 1
- 大佬,我还是有问题.alipay.system.oauth.token HOT 2
- AlipayKeyPair示例密钥与官方提供的示例所需密钥不一致 HOT 4
- 请问alipay.fund.trans.uni.transfer(单笔转账接口)是否支持 HOT 1
- php8.1兼容问题 HOT 1
- 关于证书问题:error:0906D06C:PEM routines:PEM_read_bio:no start line HOT 5
- Service Currently Unavailable HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alipay-sdk-php.