Skip to content

Commit 297f3c3

Browse files
committed
Add stubs for PDO
1 parent 170ed1f commit 297f3c3

File tree

6 files changed

+317
-157
lines changed

6 files changed

+317
-157
lines changed

ext/pdo/pdo.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ PHP_FUNCTION(pdo_drivers)
9696
}
9797
/* }}} */
9898

99-
/* {{{ arginfo */
100-
ZEND_BEGIN_ARG_INFO(arginfo_pdo_drivers, 0)
101-
ZEND_END_ARG_INFO()
102-
/* }}} */
103-
10499
/* {{{ pdo_functions[] */
105100
const zend_function_entry pdo_functions[] = {
106101
PHP_FE(pdo_drivers, arginfo_pdo_drivers)

ext/pdo/pdo.stub.php

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
/* pdo.c */
4+
5+
function pdo_drivers(): array {}
6+
7+
/* pdo_dbh.c */
8+
9+
class PDO {
10+
public function __construct(string $dsn, ?string $username = null, ?string $passwd = null, ?array $options = null) {}
11+
12+
/** @return bool */
13+
public function beginTransaction() {}
14+
15+
/** @return bool */
16+
public function commit() {}
17+
18+
/** @return string|null */
19+
public function errorCode() {}
20+
21+
/** @return array */
22+
public function errorInfo() {}
23+
24+
/** @return int|false */
25+
public function exec(string $statement) {}
26+
27+
/** @return mixed */
28+
public function getAttribute(int $attribute) {}
29+
30+
/** @return array */
31+
public static function getAvailableDrivers() {}
32+
33+
/** @return bool */
34+
public function inTransaction() {}
35+
36+
/** @return string|false */
37+
public function lastInsertId(?string $name = null) {}
38+
39+
/** @return PDOStatement|false */
40+
public function prepare(string $statement, array $driver_options = []) {}
41+
42+
/** @return PDOStatement|false */
43+
public function query(string $statement) {}
44+
45+
/** @return string|false */
46+
public function quote(string $string, int $parameter_type = PDO::PARAM_STR) {}
47+
48+
/** @return bool */
49+
public function rollBack() {}
50+
51+
/**
52+
* @param mixed $value
53+
* @return bool
54+
*/
55+
public function setAttribute(int $attribute, $value) {}
56+
}
57+
58+
/* pdo_stmt.c */
59+
60+
class PDOStatement implements Traversable {
61+
/** @return bool */
62+
public function bindColumn(mixed $column, &$param = null, int $type = 0, int $maxlen = 0, mixed $driverdata = "") {}
63+
64+
/**
65+
* @param int|string $parameter
66+
* @param mixed $driver_options
67+
* @return bool
68+
*/
69+
public function bindParam($parameter, &$variable, int $data_type = PDO::PARAM_STR, ?int $length = null, $driver_options = null) {}
70+
71+
/**
72+
* @param int|string $parameter
73+
* @param mixed $value
74+
* @return bool
75+
*/
76+
public function bindValue($parameter, $value, int $data_type = PDO::PARAM_STR) {}
77+
78+
/** @return bool */
79+
public function closeCursor() {}
80+
81+
/** @return int */
82+
public function columnCount() {}
83+
84+
/** @return void */
85+
public function debugDumpParams() {}
86+
87+
/** @return string|null */
88+
public function errorCode() {}
89+
90+
/** @return array */
91+
public function errorInfo() {}
92+
93+
/** @return bool */
94+
public function execute(?array $input_parameters = null) {}
95+
96+
/** @return mixed */
97+
public function fetch(int $fetch_style = PDO::FETCH_BOTH, int $cursor_orientation = PDO::FETCH_ORI_NEXT, int $cursor_offset = 0) {}
98+
99+
/**
100+
* @param mixed $fetch_argument
101+
* @return array|false
102+
*/
103+
public function fetchAll(int $fetch_style = PDO::FETCH_BOTH, $fetch_argument = null, array $ctor_args = []) {}
104+
105+
/** @return mixed */
106+
public function fetchColumn(int $column_number = 0) {}
107+
108+
/** @return mixed */
109+
public function fetchObject(string $class_name = "stdClass", ?array $ctor_args = null) {}
110+
111+
/** @return int|bool|string|array */
112+
public function getAttribute(int $attribute) {}
113+
114+
/** @return array|false */
115+
public function getColumnMeta(int $column) {}
116+
117+
/** @return bool */
118+
public function nextRowset() {}
119+
120+
/** @return int */
121+
public function rowCount() {}
122+
123+
/** @return bool */
124+
public function setAttribute(int $attribute, mixed $value) {}
125+
126+
/** @return bool */
127+
public function setFetchMode(int $mode) {}
128+
}

ext/pdo/pdo_arginfo.h

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/* This is a generated file, edit the .stub.php file instead. */
2+
3+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pdo_drivers, 0, 0, IS_ARRAY, 0)
4+
ZEND_END_ARG_INFO()
5+
6+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO___construct, 0, 0, 1)
7+
ZEND_ARG_TYPE_INFO(0, dsn, IS_STRING, 0)
8+
ZEND_ARG_TYPE_INFO(0, username, IS_STRING, 1)
9+
ZEND_ARG_TYPE_INFO(0, passwd, IS_STRING, 1)
10+
ZEND_ARG_TYPE_INFO(0, options, IS_ARRAY, 1)
11+
ZEND_END_ARG_INFO()
12+
13+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_beginTransaction, 0, 0, 0)
14+
ZEND_END_ARG_INFO()
15+
16+
#define arginfo_class_PDO_commit arginfo_class_PDO_beginTransaction
17+
18+
#define arginfo_class_PDO_errorCode arginfo_class_PDO_beginTransaction
19+
20+
#define arginfo_class_PDO_errorInfo arginfo_class_PDO_beginTransaction
21+
22+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_exec, 0, 0, 1)
23+
ZEND_ARG_TYPE_INFO(0, statement, IS_STRING, 0)
24+
ZEND_END_ARG_INFO()
25+
26+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_getAttribute, 0, 0, 1)
27+
ZEND_ARG_TYPE_INFO(0, attribute, IS_LONG, 0)
28+
ZEND_END_ARG_INFO()
29+
30+
#define arginfo_class_PDO_getAvailableDrivers arginfo_class_PDO_beginTransaction
31+
32+
#define arginfo_class_PDO_inTransaction arginfo_class_PDO_beginTransaction
33+
34+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_lastInsertId, 0, 0, 0)
35+
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1)
36+
ZEND_END_ARG_INFO()
37+
38+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_prepare, 0, 0, 1)
39+
ZEND_ARG_TYPE_INFO(0, statement, IS_STRING, 0)
40+
ZEND_ARG_TYPE_INFO(0, driver_options, IS_ARRAY, 0)
41+
ZEND_END_ARG_INFO()
42+
43+
#define arginfo_class_PDO_query arginfo_class_PDO_exec
44+
45+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_quote, 0, 0, 1)
46+
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
47+
ZEND_ARG_TYPE_INFO(0, parameter_type, IS_LONG, 0)
48+
ZEND_END_ARG_INFO()
49+
50+
#define arginfo_class_PDO_rollBack arginfo_class_PDO_beginTransaction
51+
52+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_setAttribute, 0, 0, 2)
53+
ZEND_ARG_TYPE_INFO(0, attribute, IS_LONG, 0)
54+
ZEND_ARG_INFO(0, value)
55+
ZEND_END_ARG_INFO()
56+
57+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_bindColumn, 0, 0, 1)
58+
ZEND_ARG_OBJ_INFO(0, column, mixed, 0)
59+
ZEND_ARG_INFO(1, param)
60+
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
61+
ZEND_ARG_TYPE_INFO(0, maxlen, IS_LONG, 0)
62+
ZEND_ARG_OBJ_INFO(0, driverdata, mixed, 0)
63+
ZEND_END_ARG_INFO()
64+
65+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_bindParam, 0, 0, 2)
66+
ZEND_ARG_INFO(0, parameter)
67+
ZEND_ARG_INFO(1, variable)
68+
ZEND_ARG_TYPE_INFO(0, data_type, IS_LONG, 0)
69+
ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 1)
70+
ZEND_ARG_INFO(0, driver_options)
71+
ZEND_END_ARG_INFO()
72+
73+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_bindValue, 0, 0, 2)
74+
ZEND_ARG_INFO(0, parameter)
75+
ZEND_ARG_INFO(0, value)
76+
ZEND_ARG_TYPE_INFO(0, data_type, IS_LONG, 0)
77+
ZEND_END_ARG_INFO()
78+
79+
#define arginfo_class_PDOStatement_closeCursor arginfo_class_PDO_beginTransaction
80+
81+
#define arginfo_class_PDOStatement_columnCount arginfo_class_PDO_beginTransaction
82+
83+
#define arginfo_class_PDOStatement_debugDumpParams arginfo_class_PDO_beginTransaction
84+
85+
#define arginfo_class_PDOStatement_errorCode arginfo_class_PDO_beginTransaction
86+
87+
#define arginfo_class_PDOStatement_errorInfo arginfo_class_PDO_beginTransaction
88+
89+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_execute, 0, 0, 0)
90+
ZEND_ARG_TYPE_INFO(0, input_parameters, IS_ARRAY, 1)
91+
ZEND_END_ARG_INFO()
92+
93+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_fetch, 0, 0, 0)
94+
ZEND_ARG_TYPE_INFO(0, fetch_style, IS_LONG, 0)
95+
ZEND_ARG_TYPE_INFO(0, cursor_orientation, IS_LONG, 0)
96+
ZEND_ARG_TYPE_INFO(0, cursor_offset, IS_LONG, 0)
97+
ZEND_END_ARG_INFO()
98+
99+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_fetchAll, 0, 0, 0)
100+
ZEND_ARG_TYPE_INFO(0, fetch_style, IS_LONG, 0)
101+
ZEND_ARG_INFO(0, fetch_argument)
102+
ZEND_ARG_TYPE_INFO(0, ctor_args, IS_ARRAY, 0)
103+
ZEND_END_ARG_INFO()
104+
105+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_fetchColumn, 0, 0, 0)
106+
ZEND_ARG_TYPE_INFO(0, column_number, IS_LONG, 0)
107+
ZEND_END_ARG_INFO()
108+
109+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_fetchObject, 0, 0, 0)
110+
ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 0)
111+
ZEND_ARG_TYPE_INFO(0, ctor_args, IS_ARRAY, 1)
112+
ZEND_END_ARG_INFO()
113+
114+
#define arginfo_class_PDOStatement_getAttribute arginfo_class_PDO_getAttribute
115+
116+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_getColumnMeta, 0, 0, 1)
117+
ZEND_ARG_TYPE_INFO(0, column, IS_LONG, 0)
118+
ZEND_END_ARG_INFO()
119+
120+
#define arginfo_class_PDOStatement_nextRowset arginfo_class_PDO_beginTransaction
121+
122+
#define arginfo_class_PDOStatement_rowCount arginfo_class_PDO_beginTransaction
123+
124+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_setAttribute, 0, 0, 2)
125+
ZEND_ARG_TYPE_INFO(0, attribute, IS_LONG, 0)
126+
ZEND_ARG_OBJ_INFO(0, value, mixed, 0)
127+
ZEND_END_ARG_INFO()
128+
129+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_setFetchMode, 0, 0, 1)
130+
ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0)
131+
ZEND_END_ARG_INFO()

ext/pdo/pdo_dbh.c

Lines changed: 21 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@ static PHP_METHOD(PDO, getAttribute)
899899
}
900900
/* }}} */
901901

902-
/* {{{ proto int PDO::exec(string query)
903-
Execute a query that does not return a row set, returning the number of affected rows */
902+
/* {{{ proto int PDO::exec(string statement)
903+
Execute a statement that does not return a row set, returning the number of affected rows */
904904
static PHP_METHOD(PDO, exec)
905905
{
906906
pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS);
@@ -928,8 +928,8 @@ static PHP_METHOD(PDO, exec)
928928
}
929929
/* }}} */
930930

931-
/* {{{ proto string PDO::lastInsertId([string seqname])
932-
Returns the id of the last row that we affected on this connection. Some databases require a sequence or table name to be passed in. Not always meaningful. */
931+
/* {{{ proto string PDO::lastInsertId([string name])
932+
Returns the id of the last row that we affected on this connection. Some databases require a sequence or table name to be passed in. Not always meaningful. */
933933
static PHP_METHOD(PDO, lastInsertId)
934934
{
935935
pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS);
@@ -989,7 +989,7 @@ static PHP_METHOD(PDO, errorCode)
989989
}
990990
/* }}} */
991991

992-
/* {{{ proto int PDO::errorInfo()
992+
/* {{{ proto array PDO::errorInfo()
993993
Fetch extended error information associated with the last operation on the database handle */
994994
static PHP_METHOD(PDO, errorInfo)
995995
{
@@ -1120,7 +1120,7 @@ static PHP_METHOD(PDO, query)
11201120
/* }}} */
11211121

11221122
/* {{{ proto string PDO::quote(string string [, int paramtype])
1123-
quotes string for use in a query. The optional paramtype acts as a hint for drivers that have alternate quoting styles. The default value is PDO_PARAM_STR */
1123+
quotes string for use in a query. The optional paramtype acts as a hint for drivers that have alternate quoting styles. The default value is PDO_PARAM_STR */
11241124
static PHP_METHOD(PDO, quote)
11251125
{
11261126
pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS);
@@ -1171,61 +1171,22 @@ static PHP_METHOD(PDO, getAvailableDrivers)
11711171
}
11721172
/* }}} */
11731173

1174-
/* {{{ arginfo */
1175-
ZEND_BEGIN_ARG_INFO_EX(arginfo_pdo___construct, 0, 0, 1)
1176-
ZEND_ARG_INFO(0, dsn)
1177-
ZEND_ARG_INFO(0, username)
1178-
ZEND_ARG_INFO(0, passwd)
1179-
ZEND_ARG_INFO(0, options) /* array */
1180-
ZEND_END_ARG_INFO()
1181-
1182-
ZEND_BEGIN_ARG_INFO_EX(arginfo_pdo_prepare, 0, 0, 1)
1183-
ZEND_ARG_INFO(0, statement)
1184-
ZEND_ARG_INFO(0, options) /* array */
1185-
ZEND_END_ARG_INFO()
1186-
1187-
ZEND_BEGIN_ARG_INFO(arginfo_pdo_setattribute, 0)
1188-
ZEND_ARG_INFO(0, attribute)
1189-
ZEND_ARG_INFO(0, value)
1190-
ZEND_END_ARG_INFO()
1191-
1192-
ZEND_BEGIN_ARG_INFO(arginfo_pdo_getattribute, 0)
1193-
ZEND_ARG_INFO(0, attribute)
1194-
ZEND_END_ARG_INFO()
1195-
1196-
ZEND_BEGIN_ARG_INFO(arginfo_pdo_exec, 0)
1197-
ZEND_ARG_INFO(0, query)
1198-
ZEND_END_ARG_INFO()
1199-
1200-
ZEND_BEGIN_ARG_INFO_EX(arginfo_pdo_lastinsertid, 0, 0, 0)
1201-
ZEND_ARG_INFO(0, seqname)
1202-
ZEND_END_ARG_INFO()
1203-
1204-
ZEND_BEGIN_ARG_INFO_EX(arginfo_pdo_quote, 0, 0, 1)
1205-
ZEND_ARG_INFO(0, string)
1206-
ZEND_ARG_INFO(0, paramtype)
1207-
ZEND_END_ARG_INFO()
1208-
1209-
ZEND_BEGIN_ARG_INFO(arginfo_pdo__void, 0)
1210-
ZEND_END_ARG_INFO()
1211-
/* }}} */
1212-
12131174
const zend_function_entry pdo_dbh_functions[] = /* {{{ */ {
1214-
ZEND_MALIAS(PDO, __construct, dbh_constructor, arginfo_pdo___construct, ZEND_ACC_PUBLIC)
1215-
PHP_ME(PDO, prepare, arginfo_pdo_prepare, ZEND_ACC_PUBLIC)
1216-
PHP_ME(PDO, beginTransaction, arginfo_pdo__void, ZEND_ACC_PUBLIC)
1217-
PHP_ME(PDO, commit, arginfo_pdo__void, ZEND_ACC_PUBLIC)
1218-
PHP_ME(PDO, rollBack, arginfo_pdo__void, ZEND_ACC_PUBLIC)
1219-
PHP_ME(PDO, inTransaction, arginfo_pdo__void, ZEND_ACC_PUBLIC)
1220-
PHP_ME(PDO, setAttribute, arginfo_pdo_setattribute, ZEND_ACC_PUBLIC)
1221-
PHP_ME(PDO, exec, arginfo_pdo_exec, ZEND_ACC_PUBLIC)
1222-
PHP_ME(PDO, query, NULL, ZEND_ACC_PUBLIC)
1223-
PHP_ME(PDO, lastInsertId, arginfo_pdo_lastinsertid, ZEND_ACC_PUBLIC)
1224-
PHP_ME(PDO, errorCode, arginfo_pdo__void, ZEND_ACC_PUBLIC)
1225-
PHP_ME(PDO, errorInfo, arginfo_pdo__void, ZEND_ACC_PUBLIC)
1226-
PHP_ME(PDO, getAttribute, arginfo_pdo_getattribute, ZEND_ACC_PUBLIC)
1227-
PHP_ME(PDO, quote, arginfo_pdo_quote, ZEND_ACC_PUBLIC)
1228-
PHP_ME(PDO, getAvailableDrivers, arginfo_pdo__void, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
1175+
ZEND_MALIAS(PDO, __construct, dbh_constructor, arginfo_class_PDO___construct, ZEND_ACC_PUBLIC)
1176+
PHP_ME(PDO, prepare, arginfo_class_PDO_prepare, ZEND_ACC_PUBLIC)
1177+
PHP_ME(PDO, beginTransaction, arginfo_class_PDO_beginTransaction, ZEND_ACC_PUBLIC)
1178+
PHP_ME(PDO, commit, arginfo_class_PDO_commit, ZEND_ACC_PUBLIC)
1179+
PHP_ME(PDO, rollBack, arginfo_class_PDO_rollBack, ZEND_ACC_PUBLIC)
1180+
PHP_ME(PDO, inTransaction, arginfo_class_PDO_inTransaction, ZEND_ACC_PUBLIC)
1181+
PHP_ME(PDO, setAttribute, arginfo_class_PDO_setAttribute, ZEND_ACC_PUBLIC)
1182+
PHP_ME(PDO, exec, arginfo_class_PDO_exec, ZEND_ACC_PUBLIC)
1183+
PHP_ME(PDO, query, arginfo_class_PDO_query, ZEND_ACC_PUBLIC)
1184+
PHP_ME(PDO, lastInsertId, arginfo_class_PDO_lastInsertId, ZEND_ACC_PUBLIC)
1185+
PHP_ME(PDO, errorCode, arginfo_class_PDO_errorCode, ZEND_ACC_PUBLIC)
1186+
PHP_ME(PDO, errorInfo, arginfo_class_PDO_errorInfo, ZEND_ACC_PUBLIC)
1187+
PHP_ME(PDO, getAttribute, arginfo_class_PDO_getAttribute, ZEND_ACC_PUBLIC)
1188+
PHP_ME(PDO, quote, arginfo_class_PDO_quote, ZEND_ACC_PUBLIC)
1189+
PHP_ME(PDO, getAvailableDrivers, arginfo_class_PDO_getAvailableDrivers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
12291190
PHP_FE_END
12301191
};
12311192
/* }}} */

0 commit comments

Comments
 (0)