Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77502 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47386 invoked from network); 23 Sep 2014 07:05:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Sep 2014 07:05:24 -0000 Authentication-Results: pb1.pair.com header.from=martin.keckeis1@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=martin.keckeis1@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.178 as permitted sender) X-PHP-List-Original-Sender: martin.keckeis1@gmail.com X-Host-Fingerprint: 209.85.214.178 mail-ob0-f178.google.com Received: from [209.85.214.178] ([209.85.214.178:41928] helo=mail-ob0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/95-09206-2BB11245 for ; Tue, 23 Sep 2014 03:05:23 -0400 Received: by mail-ob0-f178.google.com with SMTP id va2so4706356obc.9 for ; Tue, 23 Sep 2014 00:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=huAs12cVYjiuvPG7c4tbIYCNLdRJDiJ1WMiSxcAzG8E=; b=hZJSvkYQKyuZP933oM+DJndmGgmLZZcbsvqukbUTIBgm4VTbZXYzlJXAgEZexcXOZW REnYxQ/hDI33G41lH6+8upiooe8MakpI+v3JFlUNvwwO6z0690IIk5h/R8RknZlQUws9 ul4MXr0rvDM8CvXx3h+0HOEs0u36JpqbPO7zQM9Ui8+kr5XO0yf3wdrcqoEWigRPl7yD fnlNCMT1NRYIfgmrTS+4T2drbEuUUDf/6x6woO666LO5ZpbU3gFk7VyCdSEXKhS3m7uS x+XZl/dWoNK2adb8nhE2N3xxklYbcdxlRJJSu6avMj+vqD8IsjfGmfCc7kOMWT0mIqld kqhw== MIME-Version: 1.0 X-Received: by 10.182.43.201 with SMTP id y9mr31352829obl.34.1411455918808; Tue, 23 Sep 2014 00:05:18 -0700 (PDT) Received: by 10.202.212.11 with HTTP; Tue, 23 Sep 2014 00:05:18 -0700 (PDT) Date: Tue, 23 Sep 2014 09:05:18 +0200 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=001a11c2d10aa825c40503b6303b Subject: Little switch improvement: get the used variable From: martin.keckeis1@gmail.com (Martin Keckeis) --001a11c2d10aa825c40503b6303b Content-Type: text/plain; charset=UTF-8 Hello together, i often write switches, where i throw an Exception when something unknown come in, rather than using a default value. switch($myVar){ case 1: doSomethingElse(); break; case 2: doSomething(); break; //... default: throw new Exception('Undefined input: ' . $myVar); break; } I would like to write something like this: switch($myVar){ //... default: throw new Exception('Undefined input: ' . get_the_used_switch_variable()); break; } The `get_the_used_switch_variable()` is just a placeholder, name can be changed to something natural...maybe a constant. It's really usefull, when dealing with nested objects like when you work with Doctrine. Best regards Martin --001a11c2d10aa825c40503b6303b--