need get_class() equivalent that preserves case

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xandor
Forum Newbie
Posts: 17
Joined: Fri Jul 09, 2004 9:32 am

need get_class() equivalent that preserves case

Post by xandor »

My hosting service uses PHP 4.2 and when I call get_class() it returns the classname in all lower case. Does anybody know a workaround for this? I'm just passing an instance of a class and need its name. I've tried print_r, gettype, and even serialize() and they all behave the same way!
Anywhere else to hack into it?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

This is what get_class() does in this version of php (changes in php 5). One work around would be to have a convention when naming your classes - ALL_CAPS, First_case_cap, all_lower - and then you can simply call get_class() and do the required formating - strtoupper...etc.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

alternately, you could use a convention where you store the name of the class in its declaration.. i.e.

Code: Select all

<?php

class fOO
{
  var $classname = "fOO";
}

// or

class bAr
{
  function get_class()
  {
    return "bAr";
  }
}

?>
Post Reply