How to access variables or methods of the parent class in php

use the double colon(::) and parent keyword to access the variables or methods of the parent class in php

  1. class myparent {
  2. function myfunction() {
  3. echo "parent method";
  4. }
  5. }
  6.  
  7. class mychild extends myparent {
  8. function myfunc()[
  9. parent::myfunction();
  10. }
  11. }

, , , ,

  1. No comments yet.
(will not be published)
Submit Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Subscribe to comments feed
  1. No trackbacks yet.

SetPageWidth