----------  Forwarded Message  ----------
Subject: FW: [PHP-DEV] print_r
Date: Wed, 1 Aug 2001 08:19:09 +0300
From: "Emanuel Dejanu" <[EMAIL PROTECTED]>


Sorry to forward this to you but I really have problems in
printing a doubled linked class.
Can you take a look at the following message and give me
an answer.

Thanks,

Emanuel Dejanu

-----Original Message-----
From: Emanuel Dejanu [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 31, 2001 9:22 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DEV] print_r



Hi,

Is there a posibility to print an object but to not print some fields.

If I use print_r he will print all variabiles from my object, but I want on
variabile to not be printed. I do not want to write my own function.
Ex.

class Node {
        var $name;
        var $parent = '/'
        var $children = array();
        function Node($name, &$parent) {
                $this->parent = &$parent;
                $this->name = $name;
        }
}

$rootNode = new Node('root', '');
array_push($rootNode->children, new Node('child1', $rootNode));
$child1Node = &$rootNode->children[0];
array_push($child1Node->children, new Node('child1', $child1Node));

print_r($rootNode);

will print make a recursivity. What will be nice is to allow that some
variabiles to not
be printed like this:

class Node {
        var $name;
        var $__parent = '/'
        var $children = array();
        function Node($name, &$parent) {
                $this->__parent = &$parent;
                $this->name = $name;
        }
}

..... /* add the root and childrens */

print_r($rootNode);

will print now the corret tree.

Bellow you find the only modification that need to be done for this to work.

Best regards,

Emanuel Dejanu


File: Zend/zend.c

static void print_hash(HashTable *ht, int indent)
{
        zval **tmp;
        char *string_key;
        HashPosition iterator;
        unsigned long num_key, str_len;
        int i, key_type;  /****** HERE *****/

        for (i=0; i<indent; i++) {
                ZEND_PUTS(" ");
        }
        ZEND_PUTS("(\n");
        indent += PRINT_ZVAL_INDENT;
        zend_hash_internal_pointer_reset_ex(ht, &iterator);
        while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) ==
SUCCESS) {


/******** HERE **************/

                key_type = zend_hash_get_current_key_ex(ht, &string_key, &str_len,
&num_key, 0, &iterator);
                if (key_type == HASH_KEY_IS_STRING)
                        if (string_key[0] == '_' && string_key[1] == '_') continue;


/******* HERE **************/


                for (i=0; i<indent; i++) {
                        ZEND_PUTS(" ");
                }
                ZEND_PUTS("[");
                switch (key_type) {
                        case HASH_KEY_IS_STRING:
                                ZEND_PUTS(string_key);
                                break;
                        case HASH_KEY_IS_LONG:
                                zend_printf("%ld",num_key);
                                break;
                }
                ZEND_PUTS("] => ");
                zend_print_zval_r(*tmp, indent+PRINT_ZVAL_INDENT);
                ZEND_PUTS("\n");
                zend_hash_move_forward_ex(ht, &iterator);
        }
        indent -= PRINT_ZVAL_INDENT;
        for (i=0; i<indent; i++) {
                ZEND_PUTS(" ");
        }
        ZEND_PUTS(")\n");
}


--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]
-------------------------------------------------------

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to