From a7af382874a2b4fcb7dabf01b400bd06a162fc74 Mon Sep 17 00:00:00 2001 From: Andi Gutmans Date: Wed, 28 Jul 1999 17:58:38 +0000 Subject: - Added get_class($obj), get_parent_class($obj) and method_exists($obj,"name") --- ChangeLog | 3 ++ ext/standard/basic_functions.c | 71 +++++++++++++++++++++++++++++++++++++++--- ext/standard/basic_functions.h | 4 +++ ext/standard/soundex.c | 20 ++++++------ tests/testobj | 20 ++++++++++-- 5 files changed, 101 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70b5e70b7f..805164d142 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ PHP 4.0 CHANGE LOG ChangeLog ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ??? ?? 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 constructor of their own. - Fixed runtime inheritence of classes (parent methods/properties were diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 9ca142281e..2bcd11b2b9 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -272,6 +272,9 @@ function_entry basic_functions[] = { PHP_FE(is_string, first_arg_allow_ref) PHP_FE(is_array, 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(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_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(is_long) +{ + php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, 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); +} + +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) { diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 10190ebe07..20d88ca478 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -93,6 +93,10 @@ PHP_FUNCTION(is_string); PHP_FUNCTION(is_array); PHP_FUNCTION(is_object); +PHP_FUNCTION(get_class); +PHP_FUNCTION(get_parent_class); +PHP_FUNCTION(method_exists); + PHP_FUNCTION(leak); PHP_FUNCTION(error_log); diff --git a/ext/standard/soundex.c b/ext/standard/soundex.c index fc2d81c3d1..1d855b412b 100644 --- a/ext/standard/soundex.c +++ b/ext/standard/soundex.c @@ -29,7 +29,7 @@ PHP_FUNCTION(soundex) { char *somestring; - int i, small, len, code, last; + int i, _small, len, code, last; pval *arg; char soundex[4 + 1]; @@ -73,16 +73,16 @@ PHP_FUNCTION(soundex) /* build soundex string */ 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 */ /* BUG: should also map here accented letters used in non */ /* English words or names (also found in English text!): */ /* esstsett, thorn, n-tilde, c-cedilla, s-caron, ... */ code = toupper(somestring[i]); if (code >= 'A' && code <= 'Z') { - if (small == 0) { + if (_small == 0) { /* remember first valid char */ - soundex[small++] = code; + soundex[_small++] = code; last = soundex_table[code - 'A']; } else { @@ -92,7 +92,7 @@ PHP_FUNCTION(soundex) code = soundex_table[code - 'A']; if (code != last) { if (code != 0) { - soundex[small++] = code; + soundex[_small++] = code; } last = code; } @@ -100,13 +100,13 @@ PHP_FUNCTION(soundex) } } /* pad with '0' and terminate with 0 ;-) */ - while (small < 4) { - soundex[small++] = '0'; + while (_small < 4) { + soundex[_small++] = '0'; } - soundex[small] = '\0'; + soundex[_small] = '\0'; - return_value->value.str.val = estrndup(soundex, small); - return_value->value.str.len = small; + return_value->value.str.val = estrndup(soundex, _small); + return_value->value.str.len = _small; return_value->type = IS_STRING; } /* }}} */ diff --git a/tests/testobj b/tests/testobj index 7519583cc8..8db3a4136e 100644 --- a/tests/testobj +++ b/tests/testobj @@ -1,14 +1,30 @@ initialized = 1; } }; +class barbara extends foobar { + +}; +} + $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->visible = true; //sleep(5); -- cgit v1.2.1