Re: PHP5 oop question...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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\](.*?)\[\/B\]@sim",
>> "@\[U\](.*?)\[\/U\]@sim", "@\[I\](.*?)\[\/I\]@sim",
>>                            "@\[URL=([^\]]*)\]([^\[]*?)\[\/URL\]@sim",
>>                            "@\[IMG=([^\]]*)\]@semi",
>>                           
>> "@\[QUOTE=([^\]]*)\]([^\[]*?)\[\/QUOTE\]@semi"
>>                             );
>>
>>         $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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux