1

I saw code that contained the following line:

preg_replace_callback($regex, 'TextileParser::replaceAnchor', $text);

where TextileParser::replaceAnchor() is a private static method.

hakre
  • 193,403
  • 52
  • 435
  • 836
apaderno
  • 28,547
  • 16
  • 75
  • 90

2 Answers2

1

Yes, it is possible.

Just test it yourself:

<?php

class TestCallBack { private static function found_number($num) { return "-".$num[0]."-"; } public function find($Str) { return preg_replace_callback('/[0-9]/', 'TestCallBack::found_number', $Str); } } // Exemple $Tester = new TestCallBack; $Result = $Tester->find("54321"); var_dump($Result);

NawaMan
  • 25,129
  • 10
  • 51
  • 77
  • I reinstalled the OS on my computer, and I still have to enable PHP on it. Thank you for your reply. – apaderno Jul 20 '10 at 01:56
0

on php's website, there's this example:

http://www.php.net/manual/en/function.preg-replace-callback.php#96899

I'd assume if it's on php.net, then it's good to go.

karlw
  • 668
  • 4
  • 13
  • Comments written on php.net are not verified; the fact somebody reported that code doesn't mean PHP allows to use a private static method as callback. I noted the code reported in that comment, but I have not noticed anything in the documentation that reports it's possible. – apaderno Jul 20 '10 at 01:25