php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #38544 tryeach
Submitted: 2006-08-22 12:16 UTC Modified: 2016-12-30 23:52 UTC
Votes:2
Avg. Score:2.5 ± 1.5
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dtyschenko at soft-ukraine dot com Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 5.1.5 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dtyschenko at soft-ukraine dot com
New email:
PHP Version: OS:

 

 [2006-08-22 12:16 UTC] dtyschenko at soft-ukraine dot com
Description:
------------
Sometimes I need to run few functions that can throw new exception

Reproduce code:
---------------
<?php

$errors = array();

try {
	$Item->Title($_POST['title']);
} catch (InvalidArgument $e) {
	$errors[] = $e->getMessage();
}

try {
	$Item->Content($_POST['content']);
} catch (InvalidArgument $e) {
	$errors[] = $e->getMessage();
}

// In this case tryeach operator can be very usefull

tryeach {
	$Item->Title($_POST['title']);
	$Item->Content($_POST['content']);
} catch (InvalidArgument $e) {
	$errors[] = $e->getMessage();
}

?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-22 12:25 UTC] tony2001@php.net
What's the problem with this ?

try {
   $Item->Title($_POST['title']);
   $Item->Content($_POST['content']);
} ...
 [2006-08-22 13:20 UTC] dtyschenko at soft-ukraine dot com
The keyword is each.
When user submit the form, you show them waht he misses. With try you will show only one error.
And with tryeach all errors.
 [2016-12-30 23:52 UTC] cmb@php.net
-Package: Feature/Change Request +Package: Scripting Engine problem
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC