Nov
18
2008

OOP: Class Constants

It is recommended to read about Constants first before reading about Class Constants.

Class constants are the same as regular Constants except they are decliared within a class. Once they are decared they are accesable from all scopes of the script. Class constants simular to Constants can only contain scalar values.

Class Constants have some advantages over constants is that when declared within a class it is much cleaner code and are significantly faster than constants declared with defne().

PHP Class Constant “Hello World” Example:

class foo {
const BAR = "Hello World";
}
echo foo::BAR;

Constants in General:
Constants differ from normal variables in that you don’t use the $ symbol to declare or use them.
Must be a constant expression (not a variable, a class member, mathematical operation or a function call).

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • LinkedIn
  • Live
  • StumbleUpon
  • Technorati
  • TwitThis
Written by Adam in: 04. Object Oriented Programming |

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

WordPress Powered, Theme by TheBuckmaker.com | Add to Technorati Favorites. | RSS and Comments RSS