Skip to main content

Notice: “PRIVATE” const in PHP? wrong!

I need some const for GalleryTypes:

class wsGallery extends wsCore {
  const QUEUE     = 'requests';
  const ACCEPTED  = 'accepted';

  // This is the problem
  const PRIVATE = 1;
  const PUBLIC  = 2;
  const HIDDEN  = 3;
  const SYSTEM  = 4;
  const PROFILE = 5;
  // end

  // Construct
  public function __construct($gid) {
    parent::__construct();
  }
  $this->gallery = wsCache::galleries()->findOne(
    array('_id' => new MongoId($gid))
  );
  $this->full_images = wsCache::images()->find(
    array('gallery_id' => $gid)
  );
  // ...
}

It’s WRONG!

class wsGallery extends wsCore {
  const QUEUE     = 'requests';
  const ACCEPTED  = 'accepted';

  // This is the problem
  const _PRIVATE = 1;
  const _PUBLIC  = 2;
  const _HIDDEN  = 3;
  const _SYSTEM  = 4;
  const _PROFILE = 5;
  // end

  // Construct
  public function __construct($gid) {
    parent::__construct();
    $this->gallery = wsCache::galleries()->findOne(
      array('_id' => new MongoId($gid))
    );
    $this->full_images = wsCache::images()->find(
      array('gallery_id' => $gid)
    );
  }
  // ...
}

It’s OK… But ugly… PHP is very stupid.

If i want to get a speaking name my fist idea is:

wsGallery::PRIVATE
wsGallery::PUBLIC
wsGallery::PROTECTED

But it’s not free because it’s a locked name (for: private function asdasd() {} ) and i need to call in similar formats:

wsGallery::_PRIVATE
wsGallery::PRIVATE_GALLERY
wsGallery::PRIVATE_TYPE

I think i’s ugly and I can not understand it… WHY the PHP Parser is so bad?

Related Posts: