3 Replies - 273 Views - Last Post: 16 May 2013 - 02:37 PM Rate Topic: -----

#1 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 788
  • Joined: 06-January 09

Accessing class constants from another file

Posted 16 May 2013 - 10:48 AM

Hi all,

I'm pretty sure I just missed this in the manual or Googling, but I can't find a solid answer for the life of me -- if you use a class constant in another PHP file, do you have to require the class in that second file? As in, which one of these is correct?

This:
<?php
// File MyClass2
require_once( MyClass.php );
doSomething( MyClass:MYCONSTANT );
?>



or this:
<?php
// File MyClass2
doSomething( MyClass:MYCONSTANT );
?>



EDIT: I just realized I should probably mention, I'm using PHP 5.3.

Thanks,
Zel2008

This post has been edited by Zel2008: 16 May 2013 - 11:04 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Accessing class constants from another file

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3470
  • View blog
  • Posts: 9,973
  • Joined: 08-June 10

Re: Accessing class constants from another file

Posted 16 May 2013 - 11:05 AM

yes, you have to include every file you need code out of.
Was This Post Helpful? 1
  • +
  • -

#3 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 788
  • Joined: 06-January 09

Re: Accessing class constants from another file

Posted 16 May 2013 - 11:07 AM

Thank you Dormilich,
That's what I suspected, I just wanted to be sure.
Thanks!
Zel2008
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6021
  • View blog
  • Posts: 23,396
  • Joined: 23-August 08

Re: Accessing class constants from another file

Posted 16 May 2013 - 02:37 PM

It would be MyClass::CONSTANT; you need another : in there. You probably known that, but for future searchers.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1