TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-09-2010, 10:05 AM   #1 (permalink)
The Wanderer
 
sunwukung's Avatar
 
Join Date: Jul 2009
Location: Bristol
Posts: 8
Thanks: 0
sunwukung is on a distinguished road
Default OOP: prevent method X in context Y

I wanted to know if there was a way to prevent a method in a class being called unless it is called by a specific (non-inheritance chain) object. I'm borrowing from the Zend Bootstrapping pattern:

Code:
class abstract Config_Abstract(){
    public function runConfig(){
        //iterate over methods declared in child and execute each in turn
   }
}

class Config extends Config_Abstract(){
   publc function initGood(){
       //do some stuff
   }

   publc function initBad(){
      $this->runConfig(){//VERY BAD - CIRCULAR CODE
      }
   }
}

class Application(){
    public function run(){
        $Config = new Config();
        $Config->runConfig();//should only be executed by Application class
    }
}

$App = new App();
$App->run();
there are two methods I've thought of so far, but I wanted to know if Reflection or magic methods had something that could deal with this

1: use debug_backtrace() to detect the calling object
2: pass in a reference to the calling object in the configRun() argument

Can anyone offer some insight?
sunwukung is offline  
Reply With Quote
Old 04-09-2010, 01:21 PM   #2 (permalink)
The Wanderer
 
sunwukung's Avatar
 
Join Date: Jul 2009
Location: Bristol
Posts: 8
Thanks: 0
sunwukung is on a distinguished road
Default

I've just figured it out. The calling class (Application) should be given responsibility for executing runConfig - not the Config class...DOH!
I knew something was smelling...
sunwukung is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
class...method question... allworknoplay Absolute Beginners 10 04-18-2009 06:30 PM
Photo gallery best method to store? 9three Absolute Beginners 3 12-15-2008 10:54 PM
How to access the method of an object that is inside an object tony Advanced PHP Programming 5 11-13-2008 02:46 AM
Assigning non-static properties from a static method? delayedinsanity Advanced PHP Programming 4 07-10-2008 02:49 PM


All times are GMT. The time now is 10:02 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design