Réalisées par des traducteurs professionnels, des entreprises, des pages web ou traductions disponibles gratuitement.
===ecmascript===the following is an example in ecmascript, and therefore also applies to javascript and actionscript:===java===the following is an example in java:===objective-c===the following is an example in objective-c—implying either the openstep or foundation kit framework is used:===perl===the following is an example in perl:# without reflectionmy $foo = foo->new;$foo->hello;# orfoo->new->hello;# with reflectionmy $class = "foo"my $constructor = "new";my $method = "hello";my $f = $class->$constructor;$f->$method;# or$class->$constructor->$method;# with evaleval "new foo->hello;";===php===the following is an example in php:// without reflection$foo = new foo();$foo->hello();// with reflection$reflector = new reflectionclass('foo');$foo = $reflector->newinstance();$hello = $reflector->getmethod('hello');$hello->invoke($foo);// using callback$foo = new foo();call_user_func(array($foo, 'hello'));// using variable variables syntax$classname = 'foo';$foo = new $classname();$method = 'hello';$foo->$method();===python===the following is an example in python:# without reflectionobj = foo()obj.hello()# with reflectionclass_name = "foo"method = "hello"obj = globals()()getattr(obj, method)()# with evaleval("foo().hello()")===r===the following is an example in r:===ruby===the following is an example in ruby:# without reflectionobj = foo.newobj.hello# with reflectionclass_name = "foo"method = :helloobj = kernel.const_get(class_name).newobj.send method# with evaleval "foo.new.hello"==see also==*type introspection*self-modifying code*self-hosting*programming paradigms*list of reflective programming languages and platforms*mirror (programming)==references==notesdocuments* jonathan m. sobel and daniel p. friedman.
=== java ====== javascript ====== php ===// without reflection$foo = new foo();$foo->hello();// with reflection$reflector = new reflectionclass('foo');$foo = $reflector->newinstance();$hello = $reflector->getmethod('hello');$hello->invoke($foo);// using callback$foo = new foo();call_user_func(array($foo, 'hello'));// using variable variables syntax$classname = 'foo';$foo = new $classname();$method = 'hello';$foo->$method();=== ruby ===# without reflectionobj = foo.newobj.hello# with reflectionclass_name = "foo"method = :helloobj = kernel.const_get(class_name).newobj.send method=== objective-c ===// foo class@interface foo : nsobject- (void)hello;@end// without reflectionfoo *obj = [alloc init];hello;// with reflection in openstep, loading class and call method using variables.