0

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?

1
  • You probably saw a static function. Commented Apr 10, 2013 at 19:56

1 Answer 1

1

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

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

echo beer::whichIsBest();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.