mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
- Added get_class($obj), get_parent_class($obj) and method_exists($obj,"name")
This commit is contained in:
parent
5aa3eff94f
commit
a7af382874
@ -2,6 +2,9 @@ PHP 4.0 CHANGE LOG ChangeLog
|
|||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
|
|
||||||
??? ?? 1999, Version 4.0 Beta 2
|
??? ?? 1999, Version 4.0 Beta 2
|
||||||
|
- Added get_class($obj), get_parent_class($obj) and method_exists($obj,"name")
|
||||||
|
(Andi & Zeev)
|
||||||
|
- Fixed various inheritance problems (Andi & Zeev, libzend)
|
||||||
- Children now inherit their parent's constructor, if they do not supply a
|
- Children now inherit their parent's constructor, if they do not supply a
|
||||||
constructor of their own.
|
constructor of their own.
|
||||||
- Fixed runtime inheritence of classes (parent methods/properties were
|
- Fixed runtime inheritence of classes (parent methods/properties were
|
||||||
|
@ -272,6 +272,9 @@ function_entry basic_functions[] = {
|
|||||||
PHP_FE(is_string, first_arg_allow_ref)
|
PHP_FE(is_string, first_arg_allow_ref)
|
||||||
PHP_FE(is_array, first_arg_allow_ref)
|
PHP_FE(is_array, first_arg_allow_ref)
|
||||||
PHP_FE(is_object, first_arg_allow_ref)
|
PHP_FE(is_object, first_arg_allow_ref)
|
||||||
|
PHP_FE(get_class, NULL)
|
||||||
|
PHP_FE(get_parent_class, NULL)
|
||||||
|
PHP_FE(method_exists, NULL)
|
||||||
|
|
||||||
PHP_FE(leak, NULL)
|
PHP_FE(leak, NULL)
|
||||||
PHP_FE(error_log, NULL)
|
PHP_FE(error_log, NULL)
|
||||||
@ -1594,12 +1597,70 @@ void php3_is_type(INTERNAL_FUNCTION_PARAMETERS,int type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PHP_FUNCTION(is_long) { php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_LONG); }
|
PHP_FUNCTION(is_long)
|
||||||
PHP_FUNCTION(is_double) { php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_DOUBLE); }
|
{
|
||||||
PHP_FUNCTION(is_string) { php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_STRING); }
|
php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_LONG);
|
||||||
PHP_FUNCTION(is_array) { php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_ARRAY); }
|
}
|
||||||
PHP_FUNCTION(is_object) { php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_OBJECT); }
|
|
||||||
|
|
||||||
|
PHP_FUNCTION(is_double)
|
||||||
|
{
|
||||||
|
php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_DOUBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(is_string)
|
||||||
|
{
|
||||||
|
php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(is_array)
|
||||||
|
{
|
||||||
|
php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_ARRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(is_object)
|
||||||
|
{
|
||||||
|
php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_OBJECT);
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(get_class)
|
||||||
|
{
|
||||||
|
pval *arg;
|
||||||
|
|
||||||
|
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &arg)==FAILURE) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
if (arg->type != IS_OBJECT) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
RETURN_STRINGL(arg->value.obj.ce->name, arg->value.obj.ce->name_length, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(get_parent_class)
|
||||||
|
{
|
||||||
|
pval *arg;
|
||||||
|
|
||||||
|
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &arg)==FAILURE) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
if ((arg->type != IS_OBJECT) || !arg->value.obj.ce->parent) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
RETURN_STRINGL(arg->value.obj.ce->parent->name, arg->value.obj.ce->parent->name_length, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
PHP_FUNCTION(method_exists)
|
||||||
|
{
|
||||||
|
pval *arg1, *arg2;
|
||||||
|
|
||||||
|
if (ARG_COUNT(ht)!=2 || getParameters(ht, 2, &arg1, &arg2)==FAILURE) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
if (arg1->type != IS_OBJECT) {
|
||||||
|
RETURN_FALSE;
|
||||||
|
}
|
||||||
|
convert_to_string(arg2);
|
||||||
|
RETURN_LONG(zend_hash_exists(&arg1->value.obj.ce->function_table, arg2->value.str.val, arg2->value.str.len+1));
|
||||||
|
}
|
||||||
|
|
||||||
PHP_FUNCTION(leak)
|
PHP_FUNCTION(leak)
|
||||||
{
|
{
|
||||||
|
@ -93,6 +93,10 @@ PHP_FUNCTION(is_string);
|
|||||||
PHP_FUNCTION(is_array);
|
PHP_FUNCTION(is_array);
|
||||||
PHP_FUNCTION(is_object);
|
PHP_FUNCTION(is_object);
|
||||||
|
|
||||||
|
PHP_FUNCTION(get_class);
|
||||||
|
PHP_FUNCTION(get_parent_class);
|
||||||
|
PHP_FUNCTION(method_exists);
|
||||||
|
|
||||||
PHP_FUNCTION(leak);
|
PHP_FUNCTION(leak);
|
||||||
|
|
||||||
PHP_FUNCTION(error_log);
|
PHP_FUNCTION(error_log);
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
PHP_FUNCTION(soundex)
|
PHP_FUNCTION(soundex)
|
||||||
{
|
{
|
||||||
char *somestring;
|
char *somestring;
|
||||||
int i, small, len, code, last;
|
int i, _small, len, code, last;
|
||||||
pval *arg;
|
pval *arg;
|
||||||
char soundex[4 + 1];
|
char soundex[4 + 1];
|
||||||
|
|
||||||
@ -73,16 +73,16 @@ PHP_FUNCTION(soundex)
|
|||||||
|
|
||||||
/* build soundex string */
|
/* build soundex string */
|
||||||
last = -1;
|
last = -1;
|
||||||
for (i = 0, small = 0; i < len && small < 4; i++) {
|
for (i = 0, _small = 0; i < len && _small < 4; i++) {
|
||||||
/* convert chars to upper case and strip non-letter chars */
|
/* convert chars to upper case and strip non-letter chars */
|
||||||
/* BUG: should also map here accented letters used in non */
|
/* BUG: should also map here accented letters used in non */
|
||||||
/* English words or names (also found in English text!): */
|
/* English words or names (also found in English text!): */
|
||||||
/* esstsett, thorn, n-tilde, c-cedilla, s-caron, ... */
|
/* esstsett, thorn, n-tilde, c-cedilla, s-caron, ... */
|
||||||
code = toupper(somestring[i]);
|
code = toupper(somestring[i]);
|
||||||
if (code >= 'A' && code <= 'Z') {
|
if (code >= 'A' && code <= 'Z') {
|
||||||
if (small == 0) {
|
if (_small == 0) {
|
||||||
/* remember first valid char */
|
/* remember first valid char */
|
||||||
soundex[small++] = code;
|
soundex[_small++] = code;
|
||||||
last = soundex_table[code - 'A'];
|
last = soundex_table[code - 'A'];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -92,7 +92,7 @@ PHP_FUNCTION(soundex)
|
|||||||
code = soundex_table[code - 'A'];
|
code = soundex_table[code - 'A'];
|
||||||
if (code != last) {
|
if (code != last) {
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
soundex[small++] = code;
|
soundex[_small++] = code;
|
||||||
}
|
}
|
||||||
last = code;
|
last = code;
|
||||||
}
|
}
|
||||||
@ -100,13 +100,13 @@ PHP_FUNCTION(soundex)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* pad with '0' and terminate with 0 ;-) */
|
/* pad with '0' and terminate with 0 ;-) */
|
||||||
while (small < 4) {
|
while (_small < 4) {
|
||||||
soundex[small++] = '0';
|
soundex[_small++] = '0';
|
||||||
}
|
}
|
||||||
soundex[small] = '\0';
|
soundex[_small] = '\0';
|
||||||
|
|
||||||
return_value->value.str.val = estrndup(soundex, small);
|
return_value->value.str.val = estrndup(soundex, _small);
|
||||||
return_value->value.str.len = small;
|
return_value->value.str.len = _small;
|
||||||
return_value->type = IS_STRING;
|
return_value->type = IS_STRING;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -1,14 +1,30 @@
|
|||||||
<?
|
<?
|
||||||
|
|
||||||
|
define("endl","\n");
|
||||||
|
|
||||||
|
if (1) {
|
||||||
class foobar {
|
class foobar {
|
||||||
function foobar() {
|
function foobar() {
|
||||||
print "foobar!\n";
|
|
||||||
$this->initialized = 1;
|
$this->initialized = 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class barbara extends foobar {
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
$foo = new foobar; // or die("Unable to construct foobar\n");
|
$foo = new foobar; // or die("Unable to construct foobar\n");
|
||||||
print $foo->initialized;
|
//print $foo->initialized;
|
||||||
|
|
||||||
|
$boo = new barbara;
|
||||||
|
print get_class($foo).endl;
|
||||||
|
print get_parent_class($foo).endl;
|
||||||
|
print get_class($boo).endl;
|
||||||
|
print get_parent_class($boo).endl;
|
||||||
|
print method_exists($foo,"foobar").endl;
|
||||||
|
print method_exists($boo,"foobar").endl;
|
||||||
|
print method_exists($boo,"barbara").endl;
|
||||||
//$word = new COm("word.application");
|
//$word = new COm("word.application");
|
||||||
//$word->visible = true;
|
//$word->visible = true;
|
||||||
//sleep(5);
|
//sleep(5);
|
||||||
|
Loading…
Reference in New Issue
Block a user