Jump to content

Did is_callable change at some point?


sKunKbad

Recommended Posts

Looking at the comments on the php.net page for is_callable, it would seem that is_callable didn't take visibility into account, but when I was playing around with it, it seems like it does:

<?php

class Foo {
	public function __construct(){echo 'foo';}
	public function a(){echo 'a';}
	protected function b(){echo 'b';}
	private function c(){echo 'c';}
	public function e(){echo 'e';}
	protected function f(){echo 'f';}
}

$foo = new Foo;

$methods = ['__construct','a','b','c','e','f'];

foreach( $methods as $method ){
	if( is_callable( [ $foo, $method ] ) && strpos( $method, '_' ) !== 0 ){
		call_user_func( [ $foo, $method ] );
	}
}

echo ' should be fooae';

Did it change at some point? I've got a simple router that I'm using, and want to ensure that browsing to protected or private methods are blocked. Code similar to above would be easy to implement. Am I missing something?

Link to comment
https://forums.phpfreaks.com/topic/286736-did-is_callable-change-at-some-point/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.