Jump to content

ian0mackenzie

New Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by ian0mackenzie

  1. Ha! Good observation. Can't believe I missed that. Thanks a bunch for a really straight-forward and meaningful answer.
  2. Hello! Hope it's OK to post this here... I've looked in a few places and, while I've found a few variations of my question, I still have trouble filling in the gaps here. I'm trying to use more classes and more OOP style writing. However I've run into an interesting variable scope scenario and I don't quite understand. I have a class and I want to make a variable of hardcoded values available to each function within the class. The variable is $allowedTags = array( 'strong' => array(), 'a' => array('href' => array(),'title' => array(),'alt' => array(),'class' => array(),'id' => array()), 'em' => array(), ); This is a wordpress thing. It's used to see what HTML tags are allowed in certain form inputs. My question is in two parts. 1. What's the best way to accomplish this? The technique I'm using now is as follows: if (!class_exists("ClassName")) { class ClassName { private $allowedTags; function __construct() { $this->allowed_tags = array( 'strong' => array(), 'a' => array('href' => array(),'title' => array(),'alt' => array(),'class' => array(),'id' => array()), 'em' => array(), ); } // End __construct() function functionN(){ //This works! var_dump($this->allowed_tags); } But something is bothering me about this and it leads me to my other question: 2. Why do I have to define these values in __construct instead of at the private $allowedTags; line? I'm clearly missing something about variable scope here. Thanks so much in advance for any input you can provide!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.