php-general Digest 28 May 2007 06:59:17 -0000 Issue 4815

Topics (messages 255702 through 255702):

PHP5 oop question...
        255702 by: Andrei

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
    Hi list,

    I have a class which I use to parse simple bbcode inside some comments.
    I noticed on PHP5 that scope of preg_replace function is changed
when function is called inside a class. To the point:

[CODE]
class PHS_editor
{
    ...

    function parse_content( $str = null )
    {
        $from_arr = array( "@\[B\](.*?)\[\/[EMAIL PROTECTED]",
"@\[U\](.*?)\[\/[EMAIL PROTECTED]", "@\[I\](.*?)\[\/[EMAIL PROTECTED]",
                           "@\[URL=([^\]]*)\]([^\[]*?)\[\/[EMAIL PROTECTED]",
                           "@\[IMG=([^\]]*)[EMAIL PROTECTED]",
                           "@\[QUOTE=([^\]]*)\]([^\[]*?)\[\/[EMAIL PROTECTED]"
                            );

        $to_arr = array( '<b>\1</b>', '<u>\1</u>', '<i>\1</i>',

                         '<a href="\1" target="_blank">\2</a>',

                         "'<img src=\"'.stripslashes(
\*$this->get_image_location*( '\\1' ) ).'\" border=\"0\">'",

                         "'<table width=\"98%\" align=\"center\"
cellpadding=\"1\" cellspacing=\"0\" border=\"0\" class=\"form_type\">".
                          "<tr>".
                            "<td class=\"maintext\">'.stripslashes(
\*$this->remove_mytags*( '\\2' ) ).'</td>".
                         "</tr>".
                         "</table>'"

                         );

        if( is_null( $str ) )
            $str = $this->editor_content;
       
        return preg_replace( $from_arr, $to_arr, str_replace( "  ", "
&nbsp;", nl2br( $str ) ) );
    }

    ...
}
[/CODE]

    When it gets to parse [IMG] tags I get "Fatal error: Using $this
when not in object context in ...". So it seems they changed the scope
for preg_replace callback functions. As this function is called inside
the method shouldn't it have the scope of the class?
    Is there a workaround for this? I cannot declare a function
get_image_location which will staticly call the method bcuz I use
variables from instanced class.

    Thnx,
    Andy


--- End Message ---

Reply via email to