`
haohappy2
  • 浏览: 326348 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

how to use public private protected in PHP

阅读更多

public 表示全局,类内部外部子类都可以访问;private表示私有的,只有本类内部可以使用;protected表示受保护的,只有本类或子类或父类中可以访问;

<?
//父类
class father{
public function a(){
  echo "function a";
}
private function b(){
  echo "function b";
}
protected function c(){
  echo "function c";
}
}
//子类
class child extends father{
  function d(){
    parent::a();//调用父类的a方法
  }
  function e(){
    parent::c(); //调用父类的c方法
  }
function f(){
    parent::b(); //调用父类的b方法
  }

}
$father=new father();
$father->a();
$father->b(); //显示错误 外部无法调用私有的方法 Call to protected method father::b()
$father->c(); //显示错误 外部无法调用受保护的方法Call to private method father::c()

$chlid=new child();
$chlid->d();
$chlid->e();
$chlid->f();//显示错误 无法调用父类private的方法 Call to private method father::b()
?>

分享到:
评论

相关推荐

    VC帮助文档

    Use these lists to help locate a class that contains the functionality you are interested in.Visual C++ Programmer's Guide explains how to use the class library to program for Microsoft Windows NT®,...

    Beginning PHP 5.3

    - **User-Defined Functions:** Description of how to create and use custom functions in PHP. - **Function Parameters:** Explanation of function parameters, including default values, passing by ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    How can we use a class Foo in a header file without access to its definition? We can declare data members of type Foo* or Foo&. We can declare (but not define) functions with arguments, and/or ...

    Effective C#

    ### Effective C#: Key Insights and Best Practices #### Introduction "Effective C#" is an invaluable resource for developers ...- **Pattern:** Events allow objects to notify other objects of changes in...

    Java邮件开发Fundamentals of the JavaMail API

    your program to use IMAP instead of POP and expect everything in IMAP to be supported. Assuming your mail server supports IMAP, your JavaMail-based program can take Fundamentals of the JavaMail API...

    C 程序设计教学课件:Chapter 3 class and object.ppt

    Access control modifiers play a crucial role in managing how class members can be accessed. Public members can be accessed from anywhere, providing an interface for interacting with the object. ...

    Android代码-类似 Instagram Story 的插件,展示照片集合。

    How to Use To see how a StoriesProgressView can be added to your xml layouts, check the sample project. Overview public class YourActivity extends AppCompatActivity implements StoriesProgressView....

    ViewPager 放大缩小左右移动

    private static final boolean USE_CACHE = false; private static final int DEFAULT_OFFSCREEN_PAGES = 1; private static final int MAX_SETTLE_DURATION = 600; // ms private static final int PAGER_NEXT...

    DbfDotNet_version_1.0_Source

    In Dbf.Net you don't have to write any code, if you don't want to wait for the garbage collector to collect your individual you can call SaveChanges. Dbf.Net ADO.Net Collapse Copy Codevoid ...

    ICS delphixe10源码版

    ICS V8 is the current development release which is held in a public Version Control repository that is zipped each night for easy download. The download page above also includes the OpenSSL binaries ...

    rsa加密攻击源程序

    .How to use *********** It's very easy to use it once you know the when the attacks apply.So here are the explanations: 1.Common Modulus Attack: not really an attack but more of a tool, its ...

    SCJP6 Sun Certificated Programmer for Java 6 Study Guide (Exam 310-065) 英文原版

    - **Access Modifiers**: Understanding how to use `public`, `protected`, `private`, and package-private (default) modifiers to control access to classes, methods, and fields. - **Encapsulation**: The ...

    java试题(60道)

    这份【Java试题(60道)】涵盖了Java编程的核心内容,结合【How to use eclipse.txt】,可以帮助学习者不仅提升理论知识,还能熟练运用Eclipse这一主流的Java开发工具。通过系统地解答这些题目,可以有效地巩固Java...

    java面试宝典

    2、作用域public,private,protected,以及不写时的区别? 8 3、String 是最基本的数据类型吗? 8 4、float 型float f=3.4是否正确? 8 5、语句float f=1.3;编译能否通过? 8 6、short s1 = 1; s1 = s1 + 1;有什么错? 8...

Global site tag (gtag.js) - Google Analytics