Coverage Report

Created: 2026-09-14 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/ext/date/php_time.c
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright © The PHP Group and Contributors.                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to the Modified BSD License that is      |
6
   | bundled with this package in the file LICENSE, and is available      |
7
   | through the World Wide Web at <https://www.php.net/license/>.        |
8
   |                                                                      |
9
   | SPDX-License-Identifier: BSD-3-Clause                                |
10
   +----------------------------------------------------------------------+
11
   | Authors: Derick Rethans <derick@derickrethans.nl>                    |
12
   |          Tim Düsterhus <timwolla@php.net>                            |
13
   +----------------------------------------------------------------------+
14
 */
15
16
#include "php.h"
17
#include "Zend/zend_exceptions.h"
18
19
#include "php_time.h"
20
#include "time_arginfo.h"
21
22
zend_class_entry *php_date_ce_time_duration;
23
zend_class_entry *php_date_ce_time_timeexception;
24
25
static zend_object_handlers time_duration_object_handlers;
26
27
static zend_object *time_duration_object_create(zend_class_entry *ce)
28
7
{
29
7
  php_date_time_duration *obj = zend_object_alloc(sizeof(*obj), ce);
30
31
7
  zend_object_std_init(&obj->std, ce);
32
7
  object_properties_init(&obj->std, ce);
33
34
7
  timelib_duration_ctor_static(&obj->duration, /* seconds */ 0, /* nanoseconds */ 0, /* negative */ false);
35
36
7
  return &obj->std;
37
7
}
38
39
static zend_object *time_duration_object_clone(zend_object *object)
40
0
{
41
0
  const php_date_time_duration *obj = php_date_time_duration_from_obj(object);
42
43
0
  php_date_time_duration *new_obj = php_date_time_duration_from_obj(object->ce->create_object(object->ce));
44
45
0
  new_obj->duration = obj->duration;
46
0
  zend_objects_clone_members(&new_obj->std, &obj->std);
47
48
0
  return &new_obj->std;
49
0
}
50
51
PHP_MINIT_FUNCTION(date_time)
52
16
{
53
  /* Time\TimeException */
54
16
  php_date_ce_time_timeexception = register_class_Time_TimeException(zend_ce_exception);
55
56
  /* Time\Duration */
57
16
  memcpy(&time_duration_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
58
16
  time_duration_object_handlers.offset = offsetof(php_date_time_duration, std);
59
16
  time_duration_object_handlers.clone_obj = time_duration_object_clone;
60
16
  php_date_ce_time_duration = register_class_Time_Duration();
61
16
  php_date_ce_time_duration->create_object = time_duration_object_create;
62
16
  php_date_ce_time_duration->default_object_handlers = &time_duration_object_handlers;
63
64
16
  return SUCCESS;
65
16
}