Loading...

oops in php

Class Constants in php

  1. used for class values which do not change
  2. keyword const followed by name in all capital letters
  3. value may contain ecpressions
  4. support for visibikity modifiers since php 7.1
  5. reference with ClassName:: or self::

Example

<?php
class Clock{
public const DAY_IN_SECONDS=60*60*24;
public function tomorrow()
{
return time()+self:: DAY_IN_SECONDS;
}
}
echo clock::DAY_IN_SECONDS//86400
$clock = new Clock;
echo $clock->tomorrow();//1506456287