Note that there are some explanatory texts on larger screens.

plurals
  1. POImplicit Type Conversion for PHP Classes?
    primarykey
    data
    text
    <p>Is there a way to tell the php complier that I want a specific implicit conversion from one type to another?</p> <p>A simple example:</p> <pre><code>class Integer { public $val; } function ExampleFunc(Interger $i){...} ExamFunc(333); // 333 -&gt; Integer object with $val == 333. </code></pre> <p>[edit]... someone asked for an example. Here's an example from c#. This is a boolean type that changes value after it has been accessed once. </p> <pre><code> /// &lt;summary&gt; /// A Heisenberg style boolean that changes after it has been read. Defaults to false. /// &lt;/summary&gt; public class hbool { private bool value; private bool changed = false; public hbool() { value = false; } public hbool(bool value) { this.value = value; } public static implicit operator bool(hbool item) { return item.Value; } public static implicit operator hbool(bool item) { return new hbool(item); } public bool Value { get { if (!changed) { value = !value; changed = true; return !value; } return value; } } public void TouchValue() { bool value1 = Value; } public static hbool False { get { return new hbool(); } } public static hbool True { get { return new hbool(true); } } } [Test] public void hboolShouldChangeAfterRead() { hbool b = false; Assert.IsFalse(b); Assert.IsTrue(b); Assert.IsTrue(b); hbool b1 = false; Assert.IsFalse(b1); Assert.IsTrue(b1); Assert.IsTrue(b1); hbool b2 = true; Assert.IsTrue(b2); Assert.IsFalse(b2); Assert.IsFalse(b2); bool b3 = new hbool(); Assert.IsFalse(b3); Assert.IsFalse(b3); Assert.IsFalse(b3); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload