Jump to content

[SOLVED] Interface Help


robbyc

Recommended Posts

Hi can anyone help me possibly with an example.

 

I want to define methods AS WELL AS private class variables/properties which must be implemented by sub classes the class variables are particularly important. Is this possible using an interface? all the documentation I read seems unclear. Or is it not possible to define variables that must be implemented in sub classes?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/36527-solved-interface-help/
Share on other sites

You could use an interface.

 

<?php

  interface foo {
    private a;
    private b;
    public function geta();
  }

  class bar implements foo {
    private a = "this is a";
    private b = "this is b";
    public function geta() {
      return $this->a;
    }
  }

?>

 

Or.... If you would like to implement some of the functionality within your interface you could use abstraction.

 

<?php

  abstract class foo {
    private a = "this is a";
    private b = "this is b";
    abstract public function geta();
  }

?>

Link to comment
https://forums.phpfreaks.com/topic/36527-solved-interface-help/#findComment-173972
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.