Validation class T_VARIABLE probleem..
Dit is een class voor een ander validation script.
een hele mooie en opnieuw bruikbare code.. maar helaas met een fout erin en ik kan er zelfs niet achterkomen wat het probleem is.
De foutmelding die op het scherm te staan komt is als volgt: Parse error: syntax error, unexpected '$rule_line' (T_VARIABLE) on line 37
Weet iemand hoe dit opgelost moet worden?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
class Validation
{
protected $POST = array();
public $rules = array();
public $fields = array();
public $errors = array();
public function __construct($post)
{
$this->POST = $post;
}
public function set_rule($field, $label, $rules = NULL)
{
$this->rules[$field] = $rules;
$this->fields[$field] = $label;
}
private function _split_rules($rules)
{
return explode("|", $rules);
}
public function run()
{
foreach($this->rules as $field => $rule)
{
$rule_lines = $this->_split_rules($rule);
}
foreach ($rule_lines as $rule_line)
{
if (is_callable($this->_$rule_line)) //LINE37
{
$this->_$rule_line($field);
}
}
return true;
}
private function _error_message($field , $message)
{
$this->errors[$field] = $message;
}
/**
RULES
**/
private function preg($rule)
{
}
private function _required($input)
{
$keys = array_keys($this->POST);
if(!in_array($input, $keys))
{
return FALSE;
}
}
private function _valid_email($field)
{
return (preg_match('/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/', $this->POST[$field]));
}
private function _valid_phone($field)
{
return (preg_match('/^[0-9]+$/', $this->POST[$field]));
}
}
Alvast vriendelijk bedankt!
class Validation
{
protected $POST = array();
public $rules = array();
public $fields = array();
public $errors = array();
public function __construct($post)
{
$this->POST = $post;
}
public function set_rule($field, $label, $rules = NULL)
{
$this->rules[$field] = $rules;
$this->fields[$field] = $label;
}
private function _split_rules($rules)
{
return explode("|", $rules);
}
public function run()
{
foreach($this->rules as $field => $rule)
{
$rule_lines = $this->_split_rules($rule);
}
foreach ($rule_lines as $rule_line)
{
if (is_callable($this->_$rule_line)) //LINE37
{
$this->_$rule_line($field);
}
}
return true;
}
private function _error_message($field , $message)
{
$this->errors[$field] = $message;
}
/**
RULES
**/
private function preg($rule)
{
}
private function _required($input)
{
$keys = array_keys($this->POST);
if(!in_array($input, $keys))
{
return FALSE;
}
}
private function _valid_email($field)
{
return (preg_match('/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/', $this->POST[$field]));
}
private function _valid_phone($field)
{
return (preg_match('/^[0-9]+$/', $this->POST[$field]));
}
}
Alvast vriendelijk bedankt!
moet zijn
if (is_callable($this-> $rule_line))
en dit geldt ook voor regel 39 verwijderd de "_" van $rule_line
Marvin Houweling op 20/09/2012 13:47:08:
if (is_callable($this->_$rule_line))
moet zijn
if (is_callable($this-> $rule_line))
en dit geldt ook voor regel 39 verwijderd de "_" van $rule_line
moet zijn
if (is_callable($this-> $rule_line))
en dit geldt ook voor regel 39 verwijderd de "_" van $rule_line
Als ik dit doe krijg ik de volgende foutmelding:
"Fatal error: Cannot access empty property on line 37"
Dennis van der Vlag op 20/09/2012 13:49:47:
Als ik dit doe krijg ik de volgende foutmelding:
"Fatal error: Cannot access empty property on line 37"
"Fatal error: Cannot access empty property on line 37"
Ik zie dat ik in mijn voorbeeld een spatie heb staan... moet zijn
$this->$rule_line i.p.v. $this-> $rule_line
Toevoeging op 20/09/2012 14:23:54:
Ik kan er echt niet uitkomen wat er nou fout is ):
-----
Oh, ik zie het.
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
foreach ($rule_lines as $rule_line)
{
if (is_callable($this->_$rule_line)) //LINE37
{
$this->_$rule_line($field);
?>
foreach ($rule_lines as $rule_line)
{
if (is_callable($this->_$rule_line)) //LINE37
{
$this->_$rule_line($field);
?>
De parse error zit hier:
$this->_$rule_line
Om geen parse error te hebben, moet dat zijn:
$this->_rule_line
(zoals je trouwens doet voor alle andere variabelen met $this-> . Daar zet je ook gee '$' rechts van de '->')
Maar als ik de context bekijk, zal je wel dit bedoelen:
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
foreach ($rule_lines as $rule_line)
{
if (is_callable($rule_line)) //LINE37
{
$rule_line($field);
?>
foreach ($rule_lines as $rule_line)
{
if (is_callable($rule_line)) //LINE37
{
$rule_line($field);
?>
Gewijzigd op 20/09/2012 15:44:37 door Kris Peeters