1

What's the difference between this two types of methods of calling functions within classes:

Method One:

Myclass::returnValue('the value');

Method Two:

$returnthevalue = new MyClass();
$returnthevalue->returnValue('the value');

(Both of them print the same)

<?php

class MyClass
{
    public function returnValue($string){
        echo "<br><strong>";
        echo 'This is the value: ' . $string;
        echo "<br></strong>";
    }

}

Myclass::returnValue('some');
$returnthevalue = new MyClass();
$returnthevalue->returnValue('the value');
Tisp
  • 436
  • 2
  • 15
bfaria
  • 153
  • 1
  • 1
  • 8
  • Your first call is a static method call. And you should not call that way unless it's correctly labelled static. – Progrock Aug 25 '17 at 19:41
  • Your method name `returnValue` is also misleading. Because your method does not return anything (or rather returns null). – Progrock Aug 25 '17 at 19:43

0 Answers0