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 04:13

On Dec 1, 10:57 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Your method should be getting the bitwise expression, also. Just
> because it's a method in a class doesn't make any difference as to
> what's being called.
>
> How about some code?

The code is all kind of up there. I think maybe I haven't done a very
good job of describing the context so let me try to do better.

In the standalone function solution, the function exists in a file
that is included. That file also includes the constant definitions
(outside the function). When the file containing the constants and
functions is included any code calling the function can use the
constants when passing parameters to the function.

The method, on the other hand, will be part of a class that exists as
a singleton. I'll make the singleton available to other objects (in a
manner I haven't decided yet) and call the method from within that
object as MyClass::getInstance()->my_method ( ... ). At the time the
call is made, the flags will not be available as constants, but I'd
still like to be able to pass the human readable syntax. To do that,
I've moved the constants into my_method() with the intent of
translating the flag's variable name into its bit value at the top of
the method. That's done and I get the expression I'm expecting (1|32|
8), but not the evaluated value I need. Here's a snippet from the
method that _might_ help:

$result = $myobj->my_method ( 'arg1', 'arg2', 'PREG_FIND_RECURSIVE|
PREG_FIND_RETURNASSOC' );

At the top of the function, I have the following code to re-evaluate
the flags into their bits:

$tmp = preg_split ( '/([|&^~])/', $args,
-1 ,PREG_SPLIT_DELIM_CAPTURE );
$args = '';

foreach ( $tmp as $arg ) {
$args .= defined ( "self::$arg" ) ? constant ( "self::$arg" ) : $arg;
}

At this point, I have '1|32|8' rather than 41. I'm not sure how to
make that next step or, alternatively, to process the string more
effectively as a bit expression.

I hope that helps a little. Thanks again.

 

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

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