]> granicus.if.org Git - php/commitdiff
- Added get_class($obj), get_parent_class($obj) and method_exists($obj,"name")
authorAndi Gutmans <andi@php.net>
Wed, 28 Jul 1999 17:58:38 +0000 (17:58 +0000)
committerAndi Gutmans <andi@php.net>
Wed, 28 Jul 1999 17:58:38 +0000 (17:58 +0000)
ChangeLog
ext/standard/basic_functions.c
ext/standard/basic_functions.h
ext/standard/soundex.c
tests/testobj

index 70b5e70b7fc78577c75fd50c7c5a707e6aca4506..805164d1422f07c07b81ebaff3a507695a7c8eb8 100644 (file)
--- 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
index 9ca142281e830b9d169f177dc3ee951574ee2f2e..2bcd11b2b914391b983d8cf0700f0465d98c0240 100644 (file)
@@ -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)
 {
index 10190ebe0767a8698922fcf7ba34229e7a52ed8d..20d88ca47870a6c437eb34939b726526a44c0ba8 100644 (file)
@@ -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);
index fc2d81c3d1113e7a16b83966bbc104a3be8b2361..1d855b412b51cb3928c57521f46f5efcaa19cd11 100644 (file)
@@ -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;
 }
 /* }}} */
index 7519583cc80141d962489416a32098417f8efabf..8db3a4136ec8b7a6381fefdbb5af3fd98d4ed5c6 100644 (file)
@@ -1,14 +1,30 @@
 <?
 
+define("endl","\n");
+
+if (1) {
 class foobar {
        function foobar() {
-               print "foobar!\n";
                $this->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);