PHP: runkit_class_adopt - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

runkit_class_emancipate Runkit_Sandbox_Parent

Last updated: Sat, 27 Jan 2007

view this page in

# runkit_class_adopt

(PECL)

runkit_class_adopt -- Convert a base class to an inherited class, add ancestral methods when appropriate

## Описание

bool runkit_class_adopt ( string classname, string parentname )

## Список параметров

`classname`

  Name of class to be adopted

`parentname`

  Parent class which child class is extending

## Возвращаемые значения

Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки.

## Примеры

Пример 1. A runkit_class_adopt() example

`<?php
class myParent {
function parentFunc() {
echo "Parent Function Output\n";
}
}
class myChild {
}
runkit_class_adopt('myChild','myParent');
myChild::parentFunc();
?>`

Результат выполнения данного примера:

    Parent Function Output

## Смотрите также

runkit_class_emancipate()

add a note User Contributed Notes
runkit_class_adopt
muramas at cyberdiscordia dot org
04-Sep-2005 03:25
`Just an addition to my previous comment below: functions such as is_subclass_of(), is_a(), and the instanceof operator also do not detect the new lineage of the object; if you are using this function to simulate multiple or dynamic inheritance, you may need to implement your own method of determining class lineage.`
muramas at cyberdiscordia dot org
02-Sep-2005 03:09
`Function visibility (in PHP5) has some quirks as compared to the normal behavior with "extends". Consider the following:
class base {
public function a() { $this->b(); }
private function b() { echo "This is b()"; }
}
This will work fine:
class inherit extends base {
public function c() { $this->a(); }
}
$x = new inherit;
$x->c();
while this:
class adopt {
public function c() { $this->a(); }
}
runkit_class_adopt('adopt','base');
$x = new adopt;
$x->c();
will generate a fatal "Call to private method base::b() from context 'adopt'" error. Protected members can be called from the inherited methods, but still cannot be called from the original class (i.e. if b() were declared protected, the example would work as written, but adopt::c() still could not call base::b() directly.`
add a note
runkit_class_emancipate Runkit_Sandbox_Parent

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST