Interface echo not working

I am starting to work with
interface
I have the following code:

indent preformatted text by 4 spaces
<? interface try{ public function a(){} public function b(){} } class MyClassName implements MyInterfaceName{ public function a(){ return 'this a'; } public function b(){ return 'This is a'; } } $ob = New MyClassName; echo $ob->a(); echo '
'; echo $ob->b(); indent preformatted text by 4 spaces When I try the following echo $ob->a(); echo $ob->b(); it is not working properly. What am I doing wrong? Please advise.

Thats without meaning for anyone here because nobody knows what you want to achieve

  • what should the software do
  • what is the software doing
  • what error messages did you get
  • where do you expect an error
  • what did you when trying to fix it by yourself

and format your code, you see your own post and don’t you think it’s disgrace for anybody that’s willing to help? you have this button in the editor: </>

Regarding the editor I added the code as requested.

Regarding the my question I mentioned that the following two echoes.

Are not working properly.

echo $ob->a();

echo $ob->b();

I am not sure why your advice would be appreciated.

Still makes no sense for anyone not familar with what you want achieve.

  • what error messages did you get

Your code isn’t well formatted in the post.
If there aren’t errors this should be your current code:

<?php
interface try
{
    public function a(){}

    public function b(){}
}

class MyClassName implements MyInterfaceName
{
    public function a()
    {
        return 'this a';
    }

    public function b()
    {
        return 'this is a';
    }
}

$ob = new MyClassName;
echo $ob->a();
echo $ob->b();

If that is your code there are different issues:

  1. The interface name is try but in the class you are implementing MyInterfaceName;
  2. In the interface your defining methods in the wrong way. Methods of interfaces mustn’t have content defined. So instead of this:
    public function a(){}
    You have to use this:
    public function a();

Great.

I appreciate you putting time into this.

Sponsor our Newsletter | Privacy Policy | Terms of Service