Ticket #683 (closed Task: invalid)

Opened 5 months ago

Last modified 4 months ago

__toString() must not throw an exception

Reported by: Nowaker Owned by: Shadowhand
Priority: trivial Milestone:
Component: Libraries Version: SVN HEAD
Keywords: validation tostring exception Cc:

Description

Code:

$form = new Forge (NULL, 'New camp');
$form->set_attr('class', 'new_camp');

$form
	->input('free_places')
	->class('free_places')
	->label('Free places')
	->rules('required|numeric');

$form
	->submit('Dodaj')
	->class('submit');

echo $form->render();

Error description:

Fatal error: Method View::__toString() must not throw an exception in E:\dev\www\projekty\Kolonie_BMVC\app\controllers\camp_admin.php on line 54

When: Only on numeric.

Change History

Changed 5 months ago by Shadowhand

  • status changed from new to closed
  • resolution set to invalid

You need the rule valid_numeric.

Changed 4 months ago by Nowaker

  • keywords numeric removed
  • priority changed from major to trivial
  • status changed from closed to reopened
  • resolution deleted
  • type changed from Bug to Task

I agree - my mistake. But - should the error message be more readable than it is now?

Changed 4 months ago by Shadowhand

  • status changed from reopened to closed
  • resolution set to invalid

It's a PHP error, nothing that we can do about it.

Changed 4 months ago by Nowaker

  • keywords validation added; forge removed
  • resolution deleted
  • status changed from closed to reopened
  • component changed from Modules:Forge to Libraries

A solution:

// File: system/libraries/View.php
// Line: 184

	/**
	 * Magically converts view object to string.
	 *
	 * @return  string
	 */
	public function __toString()
	{
		try
		{
			$str = $this->render();
		}
		catch (Exception $e)
		{
			trigger_error($e->getMessage());
		}
		
		return $str;
	}

Now shows a readable error message without throwing an exception.

Changed 4 months ago by Xobb

Confirming the bug in SVN. Occurred when updated to the new ORM library. The views were working fine, but after update they seem to be broken.

BTW, the solution provided above is not working =(

Changed 4 months ago by Shadowhand

  • status changed from reopened to closed
  • resolution set to invalid

Still a PHP error, and would require massive additions of try/catch blocks to fix. It doesn't fit the Kohana philosophy to hijack the way PHP works.

Changed 4 months ago by anonymous

  • milestone deleted

Milestone 2.1.3 deleted

Note: See TracTickets for help on using tickets.