user1037355
user1037355

Reputation:

Accessing class method without calling the class into a variable php

Is it possible to use a classes methods without actually calling the class into a variable. I am sure i have seen this somewhere but i'm not sure if i was dreaming.

Take this example:

<?php
namespace proj;
class beer{
  public function whichIsBest(){
     return 'Not cheap stuff';
  }
}

Include the file start the class but then how can i get to the whishIsBest method without calling the class into a variable first.

<?php
include 'beerClass.php';
new \proj\beer();
echo \proj\beer()->whichIsBest

Or is this just not possible and I was actually dreaming?

Upvotes: 0

Views: 46

Answers (1)

Andrej  Bestuzhev
Andrej Bestuzhev

Reputation: 674

http://www.php.net/manual/en/language.oop5.static.php

class beer {
public static function whichIsBest() {
 do //
}
}
..

echo beer::whichIsBest();

Upvotes: 1

Related Questions