PHP: Can an Abstract Class Inherit From a Concrete Class?

I’ve been working on a project of late using the Yii framework.  It’s been really quite fun — I’m surprised at how easy it is to implement a project with good design standards.  I’ve also learned quite a few things about some of the dustier corners of PHP — things that I (used to be) a bit perplexed about. Qiang deserves some serious kudos.

Today I ran into a wall though.  I’ll be implementing several controllers for the project that I am working on — but I want to define an abstract class for a few common variables and some polymorphic methods.  Being that PHP doesn’t allow multiple inheritance (and rightly so I might add), I found myself wondering exactly how I would need to implement an interface for the classes I wanted to instantiate:

Can I create an abstract class that could extend from CController?

Mind you, CController is a concrete class.

To answer the question, I created a sandbox project.  I actually keep a git repository for such things — and I also have my employers create repositories too — the theory being that others (OK … me in six months when I’ve forgotten about this) can benefit from my research.  Here’s what it looked like:

<?php
/// @file inheritanceTree.php
/// @brief an inheritance tree made to answer a question that google could not

/// @brief This is the top-level class of an inheritance tree
class aaConcreteClass {
    public function foo() {
      echo __CLASS__ . "::" . __METHOD__ . "()" . "\n";
    }
}

/// @brief This is the mid-level class of an inheritance tree
abstract class bbAbstractClass extends aaConcreteClass {
    public function foo() {
       parent::foo();
       echo "\t" . __CLASS__ . "::" . __METHOD__ . "()" . "\n";
    }
    public abstract function bar();
}

/// @brief This is the bottom-level class of an inheritance tree
class ccInheritedClass extends bbAbstractClass {
    public final function foo() {
       parent::foo();
      echo "\t" . "\t" .__CLASS__ . "::" . __METHOD__ . "()" . "\n";
    }
    public final function bar() {
       echo __CLASS__ . "::" . __METHOD__ . "()" . "\n";
    }
}
?>

<?php
/// @file main.php
/// @brief This is the file that will run to answer the question

require_once 'inheritanceTree.php';

$topObject = new aaConcreteClass();
$topObject->foo();
$bottomObject = new ccInheritedClass();
$bottomObject->foo();
$bottomObject->bar();
?>

Well, the answer to this question is YES. Here is what I had print to terminal when I ran /usr/bin/php main.php:


aaConcreteClass::aaConcreteClass::foo()
aaConcreteClass::aaConcreteClass::foo()
    bbAbstractClass::bbAbstractClass::foo()
       ccInheritedClass::ccInheritedClass::foo()
ccInheritedClass::ccInheritedClass::bar()

Hot damn! I love it when I learn something!


Using Krumo PHP Dumper with Yii (The Idiot’s Method)

Krumo is a PHP development tool that makes var_dump() output readable by mere mortals. I’ve just changed jobs so that I can work on a new web app that utilizes the Yii MVC framework, and I needed a a way to deal with data dumps. While Yii does have a built in tool, it fails on two fronts:

  1. It doesn’t collapse arrays. This means that you have to sift through the data.
  2. It’s a stinking PITA to use. The default dump is no better than using var_dump()itself. To use it effectively, you run the risk of aggravating your Carpal Tunnel Syndrome:

    CVardumper::dump( $foo, 1000, true);

Eeew.

Case in point. Here is the CVardumper::dump() output for the $_SERVER variable:

CVarDumper dump

…and here is krumo::dump() of the same (along with $_GET and $_POST):

krumo var dumps

 

See what I mean?

So… how to do this — the idiotic way. I fiddle-farted around with loading it up via the arrays in /protected/config/main.php, but I didn’t get anywhere. Then I realized that the only thing that I need to do is get an require_once called when the application loads. Ergo, I cheated:

  1. Unzip the Krumo files to /protected/components/krumo.
  2. Place the following at the end of /protected/components/Controller.php:

    require_once 'krumo/class.krumo.php';

… and that’s it.

Granted, It’s probably not ‘Yii-riffic,’ but it’ll do for now :-)

Feel free to tell me how it could be done better!


Des Décharges Stupides ont Appris à Parler le Français

Ce message et toutes les pièces jointes (ci-après le “message”) sont
confidentiels et établis à l’intention exclusive de ses
destinataires.Toute utilisation ou diffusion non autorisée est
interdite.Tout message électronique est susceptible d’altération.
Robosoft décline toute responsabilité au titre de ce message s’il à
été altéré, déformé ou falsifié. Si vous n’êtes pas le destinataire de
ce message, merci de le détruire immédiatement et d’avertir
l’expéditeur.


This message and any attachments (the “message”) are confidential and
intended solely for the addressees. Any unauthorised use or
dissemination is prohibited. Messages are susceptible to alteration.
Robosoft shall not be liable for the message if altered, changed or
falsified. If you are not the intended addressee of this message,
please cancel it immediately and inform the sender.


Email Legal Disclaimers: I will disclose them — SUE ME!

I see email disclaimers all the time. Some idiot lawyer with a degree from a crackerjack box must have thought them up. They actually think that if their communication happens to fall within view of my eyes that they can assert their supposed legal right to privacy.

Were I eavesdropping, they would have a point. Electronic eavesdropping is illegal. But that’s not what they are asserting. Rather, they assert that if they (or their various and sundry recipients) act negligently and disclose such information, somehow I am liable.

I say BULLSHIT.

I’ve therefore decided to start disclosing to the world every legal disclaimer that I run across. Being that most state that their legal authority covers the contents of the email, therefore it’s reasonable to conclude that it also covers the legal disclaimer.

Here’s the very first one:

The information contained in this message is intended only for the recipient, and may be a confidential attorney-client communication or may otherwise be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, please be aware that any dissemination or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify us by replying to the message and deleting it from your computer. The McGraw-Hill Companies, Inc. reserves the right, subject to applicable local law, to monitor, review and process the content of any electronic message or information sent to or from McGraw-Hill e-mail addresses without informing the sender or recipient of the message. By sending electronic message or information to McGraw-Hill e-mail addresses you, as the sender, are consenting to McGraw-Hill processing any of your personal data therein.