|
Posted by Jerry Stuckle on 12/02/07 12:59
Rob Wilkerson wrote:
> On Dec 1, 11:46 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> No, let's see your entire method - and more importantly, the code that's
>> calling it. You shouldn't need to do any of the stuff you're doing
>> here. You have something else wrong, but my crystal ball is broken.
>> So, without the code it's impossible to see what you've got.
>
> Okay, then you need a little more background, maybe. I'm working to
> adapt someone else's custom function into an object oriented
> architecture. The original function (and definition of constants) can
> be found at http://www.pgregg.com/projects/php/preg_find/preg_find.phps.
>
> My object oriented translation requires just a few changes to the
> function itself and they're really just syntax changes - except for
> translating the bitwise expression.
>
> CALLING THE METHOD:
>
> require_once ( 'org/client/file/finder.php' );
> $finder = new Finder();
> $result = $finder->preg_find ( '/image\.php$/', '/path/to/my/includes/
> org/client/content', 'PREG_FIND_RECURSIVE|PREG_FIND_RETURNASSOC' );
> new PHPDump ( $result );
> exit();
>
> Note that the flag definitions do not exist yet. If the single quotes
> in the third argument are removed then the normal (and expected)
> "constant not defined" errors are thrown. Nor, for that matter, do I
> *want* them to exist here. I want to keep them with the code where
> they matter rather than defining them everywhere they're used.
> Similarly, I want to continue to be able to use the flags because
> they're more readable than passing in the bit values themselves.
>
> METHOD CHANGES:
>
> class Finder {
> const PREG_FIND_RECURSIVE = 1;
> const PREG_FIND_DIRMATCH = 2;
> const PREG_FIND_FULLPATH = 4;
> const PREG_FIND_NEGATE = 8;
>
> /**
> * All of the additional flag constants defined similarly
> *
> * SNIP -->
> */
>
>
> public function preg_find ( $pattern, $start_dir='.', $args=NULL ) {
> /**
> * Go through the business of evaluating the bit string.
> */
> $args_in = $args; /** Save off the input string */
> $tmp = preg_split ( '/([|&^~])/', $args,
> -1 ,PREG_SPLIT_DELIM_CAPTURE );
> $args = '';
>
> foreach ( $tmp as $arg ) {
> $args .= defined ( "self::$arg" ) ? constant ( "self::$arg" ) :
> $arg;
> }
>
> /**
> * Back to doing what we need to do using the bitwise expression
> that is expected.
> */
> static $depth = -1;
> ++$depth;
>
> /**
> * SNIP -->
> */
> }
> }
>
> Aside from the code shown at the top of the method, only the following
> changes from the original were made:
>
> - The syntax of all references to a flag within the method was changed
> to "self::FLAG_NAME".
> - In the recursive call to the method, the arguments being passed are
> the original arguments saved off at the top of the method.
>
> I've found no other changes that are required thus far.
>
> Once again, I appreciate your help.
The flags do exist in your code, because you've defined them. Your
problem is in how you're using them.
You defined the constants in the class, so you need to scope them to the
class, i.e. Finder::PREG_FIND_RECURSIVE.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|