You are here: Re: Help With Bitwise Operations « PHP Programming Language « IT news, forums, messages
Re: Help With Bitwise Operations

Posted by Rob Wilkerson on 12/02/07 10:23

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация