Completed
Push — master ( d732f2...827150 )
by smiley
01:50
created

MemzeroDestructorTrait::__destruct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 0
1
<?php
2
/**
3
 * Trait MemzeroDestructorTrait
4
 *
5
 * @filesource   MemzeroDestructorTrait.php
6
 * @created      25.01.2018
7
 * @package      chillerlan\Traits\Crypto
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2018 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Traits\Crypto;
14
15
trait MemzeroDestructorTrait{
16
17
	/**
18
	 * @return void
19
	 */
20
	public function __destruct(){
21
22
		foreach(array_keys(get_object_vars($this)) as $key){
23
24
			if(is_scalar($this->{$key})){
25
				$this->{$key} = (string)$this->{$key};
26
27
				sodium_memzero($this->{$key});
28
			}
29
30
			unset($this->{$key});
31
		}
32
33
	}
34
35
36
}
37