 |
- PHP
:
void php3_foo(INTERNAL_FUNCTION_PARAMETERS) {
} |
, .
pval. /union,
. ,
, :
E-1.
pval *arg1, *arg2;
if (ARG_COUNT(ht) != 2 || getParameters(ht,2,&arg1,&arg2)==FAILURE) {
WRONG_PARAM_COUNT;
} |
|
: .
&(pval *) getParameters.
, n- ,
ParameterPassedByReference(ht,n). 1 0.
,
, , pval_destructor
, , ARRAY, ,
, ,
internal_functions.h return_value ARRAY.
, IS_STRING,
estrdup()'
IS_STRING. ,
IS_STRING IS_ARRAY, pval_destructor.
.
2 3 , :
E-2.
pval *arg1, *arg2, *arg3;
int arg_count = ARG_COUNT(ht);
if (arg_count < 2 || arg_count > 3 ||
getParameters(ht,arg_count,&arg1,&arg2,&arg3)==FAILURE) {
WRONG_PARAM_COUNT;
} |
|
() pval.
: E-1. PHP
| IS_STRING | |
| IS_DOUBLE | |
| IS_LONG | |
| IS_ARRAY | | | IS_EMPTY |
None/ | | IS_USER_FUNCTION |
?? | | IS_INTERNAL_FUNCTION |
?? ( - - ) |
| IS_CLASS | ?? | | IS_OBJECT |
?? |
,
, :
convert_to_long(arg1);
convert_to_double(arg1);
convert_to_string(arg1);
convert_to_boolean_long(arg1); /* "" "0", 0,
1 */
convert_string_to_number(arg1); /* LONG
DOUBLE, */ |
/in-place. .
union; : IS_STRING: arg1->value.str.val
IS_LONG: arg1->value.lval IS_DOUBLE: arg1->value.dval
emalloc() estrdup(). ,
malloc()
strdup(). efree().
: ,
, ,
. ,
, emalloc()
estrdup(). ,
( ).
/ ,
/, : emalloc(), estrdup() efree().
, -. emalloc() estrdup(), efree()
, ;
. " ,
-" : efree() ,
emalloc()' estrdup()',
. , , .
"-DDEBUG", PHP
, emalloc() estrdup(),
efree(), .
, :
SET_VAR_STRING(name,value) SET_VAR_DOUBLE(name,value)
SET_VAR_LONG(name,value)
| |
SET_VAR_STRING. value
,
. SET_VAR_STRING. |
PHP -. &symbol_table
'/main' , active_symbol_table
( ,
, , ).
'active_symbol_table'.
&symbol_table, 'main'
. , .
E-3. $foo
if (hash_exists(active_symbol_table,"foo",sizeof("foo"))) { exists... }
else { doesn't exist } |
|
E-4.
hash_find(active_symbol_table,"foo",sizeof("foo"),&pvalue);
check(pvalue.type); |
|
PHP -,
. ,
.
, :
hash_exists() hash_find().
:
E-5.
pval arr;
if (array_init(&arr) == FAILURE) { failed... };
hash_update(active_symbol_table,"foo",sizeof("foo"),&arr,sizeof(pval),NULL); |
|
$foo . .
:
E-6.
pval entry;
entry.type = IS_LONG;
entry.value.lval = 5;
/* $foo["bar"] = 5 */
hash_update(arr.value.ht,"bar",sizeof("bar"),&entry,sizeof(pval),NULL);
/* $foo[7] = 5 */
hash_index_update(arr.value.ht,7,&entry,sizeof(pval),NULL);
/* $foo[],
* $foo[8], 5 ( php2)
*/
hash_next_index_insert(arr.value.ht,&entry,sizeof(pval),NULL); |
|
, ,
. ,
pval ** add , pval *-
, . NULL ( ) -
. hash_next_index_insert() ,
"$foo[] = bar;" PHP 2.0. ,
, :
if (array_init(return_value) == FAILURE) { failed...; } |
... :
add_next_index_long(return_value,long_value);
add_next_index_double(return_value,double_value);
add_next_index_string(return_value,estrdup(string_value)); |
, ,
:
pval *arr;
if (hash_find(active_symbol_table,"foo",sizeof("foo"),(void **)&arr)==FAILURE)
{ can't find... }
else { use arr->value.ht... } |
, hash_find pval, pval.
SUCCESS FAILURE ( hash_exists(), ).
return- .
RETURN_* return- : -
RETURN RETURN_FALSE RETURN_TRUE RETURN_LONG(l)
RETURN_STRING(s,dup) dup TRUE,
RETURN_STRINGL(s,l,dup) (s), (l)
RETURN_DOUBLE(d)
RETVAL_* , , return-.
RETVAL_FALSE RETVAL_TRUE RETVAL_LONG(l)
RETVAL_STRING(s,dup) dup TRUE,
RETVAL_STRINGL(s,l,dup) (s), (l)
RETVAL_DOUBLE(d) estrdup() 's',
,
, .
success/error,
RETURN_TRUE RETURN_FALSE, .
, /object /array.
: object_init(return_value). -
. , , . -
, .
, "this"
active_symbol_table. IS_OBJECT,
(.. .value.ht).
:
add_method( return_value, function_name, function_ptr );
|
: add_property_long( return_value,
property_name, l ) - 'property_name', long, 'l'
add_property_double( return_value,property_name, d ) - , double
add_property_string( return_value,property_name, str ) - , string
add_property_stringl( return_value,property_name, str, l ) - , string 'l'
: array_init(return_value)
. .
: add_assoc_long(return_value,key,l) - /entry
'key' long- 'l' add_assoc_double(return_value,key,d)
add_assoc_string(return_value,key,str,duplicate)
add_assoc_stringl(return_value,key,str,length,duplicate) -
add_index_long(return_value,index,l) - 'index' long- 'l'
add_index_double(return_value,index,d) add_index_string(return_value,index,str)
add_index_stringl(return_value,index,str,length)-
add_next_index_long(return_value,l) - long- 'l'
add_next_index_double(return_value,d)
add_next_index_string(return_value,str)
add_next_index_stringl(return_value,str,length) -
PHP .
PHP 2.0. : -
php3_list_insert(ptr, type) - 'id'
php3_list_delete(id) - id
php3_list_find(id,*type) - id,
'type'
SQL-,
; , .
:
E-7.
RESOURCE *resource;
/* ... ... */
/* */
return_value->value.lval = php3_list_insert((void *) resource, LE_RESOURCE_TYPE);
return_value->type = IS_LONG; |
|
E-8.
pval *resource_id;
RESOURCE *resource;
int type;
convert_to_long(resource_id);
resource = php3_list_find(resource_id->value.lval, &type);
if (type != LE_RESOURCE_TYPE) {
php3_error(E_WARNING,"resource index %d has the wrong type",resource_id->value.lval);
RETURN_FALSE;
}
/* ... ... */ |
|
E-9.
pval *resource_id;
RESOURCE *resource;
int type;
convert_to_long(resource_id);
php3_list_delete(resource_id->value.lval); |
|
php3_list.h, enum
list_entry_type. , shutdown-
list.c's list_entry_destructor()
( /shutdown , case).
PHP (..
, ).
MySQL, mSQL, ,
, mysql.c. :
| php3_mysql_do_connect | | php3_mysql_connect() |
| php3_mysql_pconnect() |
:
, (9).
connect-, ,
. ,
( 1., ).
, ,
,
,
,
.
(, LE_MYSQL_LINK LE_MYSQL_PLINK
- ).
mysql.c, , ,
connect, .
, 'list' 'plist': -
php3_plist_insert(ptr, type) - 'id'
php3_plist_delete(id) - id
php3_plist_find(id,*type) - id,
'type'
, , .
,
-. ,
MySQL/mSQL, pconnect() (
connect), host/user/passwd,
, SQL- /key. pconnect()
host/user/passwd, key, SQL- .
, mysql.c msql.c,
- plist'.
: ,
** PHP,
.. emalloc(), estrdup(), etc.
malloc(), strdup(), etc.
- ( ) ,
PHP, .
, PHP
, .
, ,
, .
.
, (, SQL- etc).
, **
,
. : emalloc()
, efree() .
PHP .
php3.ini, - Apache- -
Apache .conf-. Apache
.conf- ,
. ,
safemodeexecdir, , - .
, .
: -
php3_ini_structure mod_php3.h.
main.c php3_module_startup
cfg_get_string() cfg_get_long().
, php3_commands mod_php3.c.
restrictions/. RSRC_CONF ,
Apache .conf-. OR_OPTIONS
, .htaccess-.
php3take1handler() php3flaghandler() .
/configuration
_php3_info() functions/info.c .
- , , -.
php3_ini.directive.
|