1 | --TEST-- |
---|
2 | Log: _extractMessage() [Zend Engine 2.0] |
---|
3 | --SKIPIF-- |
---|
4 | <?php |
---|
5 | if (version_compare(zend_version(), "2.0.0", "<") || |
---|
6 | version_compare(zend_version(), "2.2.0", ">=")) die('skip'); |
---|
7 | ?> |
---|
8 | --FILE-- |
---|
9 | <?php |
---|
10 | |
---|
11 | require_once 'Log.php'; |
---|
12 | |
---|
13 | $conf = array('lineFormat' => '%2$s [%3$s] %4$s'); |
---|
14 | $logger = &Log::singleton('console', '', 'ident', $conf); |
---|
15 | |
---|
16 | /* Logging a regular string. */ |
---|
17 | $logger->log('String'); |
---|
18 | |
---|
19 | /* Logging a bare object. */ |
---|
20 | class BareObject {} |
---|
21 | $logger->log(new BareObject()); |
---|
22 | |
---|
23 | /* Logging an object with a getMessage() method. */ |
---|
24 | class GetMessageObject { function getMessage() { return "getMessage"; } } |
---|
25 | $logger->log(new GetMessageObject()); |
---|
26 | |
---|
27 | /* Logging an object with a toString() method. */ |
---|
28 | class ToStringObject { function toString() { return "toString"; } } |
---|
29 | $logger->log(new ToStringObject()); |
---|
30 | |
---|
31 | /* Logging an object with a __toString() method using casting. */ |
---|
32 | class CastableObject { function __toString() { return "__toString"; } } |
---|
33 | $logger->log(new CastableObject()); |
---|
34 | |
---|
35 | /* Logging a PEAR_Error object. */ |
---|
36 | require_once 'PEAR.php'; |
---|
37 | $logger->log(new PEAR_Error('PEAR_Error object', 100)); |
---|
38 | |
---|
39 | /* Logging an array. */ |
---|
40 | $logger->log(array(1, 2, 'three' => 3)); |
---|
41 | |
---|
42 | /* Logging an array with scalar 'message' keys. */ |
---|
43 | $logger->log(array('message' => 'Message Key')); |
---|
44 | $logger->log(array('message' => 50)); |
---|
45 | |
---|
46 | /* Logging an array with a non-scalar 'message' key. */ |
---|
47 | $logger->log(array('message' => array(1, 2, 3))); |
---|
48 | |
---|
49 | --EXPECT-- |
---|
50 | ident [info] String |
---|
51 | ident [info] BareObject::__set_state(array( |
---|
52 | )) |
---|
53 | ident [info] getMessage |
---|
54 | ident [info] toString |
---|
55 | ident [info] Object id #2 |
---|
56 | ident [info] PEAR_Error object |
---|
57 | ident [info] array ( |
---|
58 | 0 => 1, |
---|
59 | 1 => 2, |
---|
60 | 'three' => 3, |
---|
61 | |
---|
62 | ident [info] Message Key |
---|
63 | ident [info] 50 |
---|
64 | ident [info] array ( |
---|
65 | 0 => 1, |
---|
66 | 1 => 2, |
---|
67 | 2 => 3, |
---|
68 | ) |
---|