gpt4 book ai didi

php - PHP 中类方法的默认可见性

转载 作者:IT老高 更新时间:2023-10-28 11:48:58 24 4
gpt4 key购买 nike

我看了manual ,但我似乎找不到答案。

没有可见性声明的方法在 PHP 中的默认可见性是什么? PHP 是否像 Java 一样具有包可见性?

例如,在下面的代码中,go()是public还是private?

class test {
function go() {
}
}

我问的原因是我见过很多构造函数代码写成function __construct(),还有一些写成public function __construct()。它们是等价的吗?

最佳答案

默认是公开的。

Class methods may be defined as public, private, or protected. Methods declared without any explicit visibility keyword are defined as public.

http://www.php.net/manual/en/language.oop5.visibility.php

关于php - PHP 中类方法的默认可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2224380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com