Skip to content

Commit 3c49281

Browse files
authored
Merge pull request #208 from viest/dev
Fix: read: Turning data into custom types
2 parents 8ba232c + 7000ccf commit 3c49281

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

kernel/read.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ void data_to_custom_type(const char *string_value, zend_ulong type, zval *zv_res
162162

163163
{
164164
zend_long _long = 0; double _double = 0;
165-
is_numeric_string(string_value, strlen(string_value), &_long, &_double, 0);
165+
166+
if (!(type & READ_TYPE_STRING)) {
167+
is_numeric_string(string_value, strlen(string_value), &_long, &_double, 0);
168+
}
166169

167170
if (Z_TYPE_P(zv_result_t) == IS_ARRAY) {
168171
if (_double > 0) {

tests/fix-207.phpt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
--TEST--
2+
Check for vtiful presence
3+
--SKIPIF--
4+
<?php
5+
require __DIR__ . '/include/skipif.inc';
6+
skip_disable_reader();
7+
?>
8+
--FILE--
9+
<?php
10+
$config = ['path' => './tests'];
11+
$excel = new \Vtiful\Kernel\Excel($config);
12+
13+
$filePath = $excel->fileName('tutorial.xlsx')
14+
->header(['Name', 'Code'])
15+
->data([
16+
['Viest', '00024']
17+
])
18+
->output();
19+
20+
$dataOne = $excel->openFile('tutorial.xlsx')
21+
->openSheet()
22+
->setType([
23+
\Vtiful\Kernel\Excel::TYPE_STRING,
24+
\Vtiful\Kernel\Excel::TYPE_STRING,
25+
])
26+
->getSheetData();
27+
28+
$dataTwo = $excel->openFile('tutorial.xlsx')
29+
->openSheet()
30+
->setType([
31+
\Vtiful\Kernel\Excel::TYPE_STRING,
32+
\Vtiful\Kernel\Excel::TYPE_INT,
33+
])
34+
->getSheetData();
35+
36+
var_dump($dataOne);
37+
var_dump($dataTwo);
38+
?>
39+
--CLEAN--
40+
<?php
41+
@unlink(__DIR__ . '/tutorial.xlsx');
42+
?>
43+
--EXPECT--
44+
array(2) {
45+
[0]=>
46+
array(2) {
47+
[0]=>
48+
string(4) "Name"
49+
[1]=>
50+
string(4) "Code"
51+
}
52+
[1]=>
53+
array(2) {
54+
[0]=>
55+
string(5) "Viest"
56+
[1]=>
57+
string(5) "00024"
58+
}
59+
}
60+
array(2) {
61+
[0]=>
62+
array(2) {
63+
[0]=>
64+
string(4) "Name"
65+
[1]=>
66+
string(4) "Code"
67+
}
68+
[1]=>
69+
array(2) {
70+
[0]=>
71+
string(5) "Viest"
72+
[1]=>
73+
int(24)
74+
}
75+
}

tests/open_xlsx_get_data_with_set_type.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ array(2) {
4848
[0]=>
4949
string(5) "Viest"
5050
[1]=>
51-
int(24)
51+
string(2) "24"
5252
[2]=>
5353
int(1568877706)
5454
}

0 commit comments

Comments
 (0)