Stut wrote:
> Andrei wrote:
>>     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.
>
> How are you trying to use this class? It sounds like you're trying to
> use the method statically. When a method is called statically it does
> not have a $this.
>
> -Stut
>
    Yes, method was called staticly. Strange tho in php 4 it worked.
    Thnx for enlighting me with this.

    Andy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to