[PHP-DEV] BC break with php 5.2.6

2008-03-27 Thread Marco Kaiser
Hi,

i noticed that some changes was made that 100% break all apps that do such
stuff:

class x extends y
{
public static function foo()
{
new self();
}
}

class y
{
private function __construct()
{
echo 'y::__construct()' . PHP_EOL;
}
}

x::foo();

with php 5.2.5 i works so that i get an output y::__construct() but with
5.2.6RC and -DEV
it throws an fatal error:

Fatal error: Call to private y::__construct() from context 'x'

i can remember that i asked a related question last year and someone told me
it is ok so and its a know behavior.
This change will ie. break ZF too. Any suggestions to this behavior?

-- 
Marco Kaiser


[PHP-DEV] RE: [PHP-QA] BC break with php 5.2.6

2008-03-27 Thread Marco Kaiser
Hi Marcus,

thanks for this conclusion. I just asked this because this changed in this
release and should noticed in the readme or upgrade process because most
singleton pattern implementations in some frameworks, for ie. ZF are using
this code:

class My_Controller_Front extends Zend_Controller_Front
{
public static function getInstance()
{
if (null === self::$_instance) {
self::$_instance = new self();
}

return self::$_instance;
}
}

The __constructor in Zend_Controller_Front is private.
I asked a, i think, similar question last nov. About private properties.
http://news.php.net/php.internals/33543

Johannes replied to this:

http://news.php.net/php.internals/33544

Johannes:  That's a feature: Extended classes know nothing about private
stuff in
the parent class. Without that the encapsulation won't be complete.

This means this was maybe a bug, that i allread talked about but its now
changed so we should raise a notice about this. That will BREAK
Many many apps out there.

For example, PHPUNIT, ZendFramework, ezComponents.

-- Marco

 -Original Message-
 From: Marcus Boerger [mailto:[EMAIL PROTECTED]
 Sent: Thursday, March 27, 2008 10:51 AM
 To: Marco Kaiser
 Cc: PHP Developers Mailing List; [EMAIL PROTECTED]
 Subject: Re: [PHP-QA] BC break with php 5.2.6
 
 Hello Marco,
 
 Thursday, March 27, 2008, 9:25:48 AM, you wrote:
 
  Hi,
 
  i noticed that some changes was made that 100% break all apps that do
 such
  stuff:
 
  class x extends y
  {
  public static function foo()
  {
  new self();
  }
  }
 
  class y
  {
  private function __construct()
  {
  echo 'y::__construct()' . PHP_EOL;
  }
  }
 
  x::foo();
 
  with php 5.2.5 i works so that i get an output y::__construct() but
 with
  5.2.6RC and -DEV
  it throws an fatal error:
 
  Fatal error: Call to private y::__construct() from context 'x'
 
 The behavior is correct. Maybe something with $this is broken in
 earlier
 versions. I checked the basic issue here calling an inherited private
 constructor directly without anything else involved:
 
 [EMAIL PROTECTED] PHP_5_0]$ php -r 'class R{private function
 __construct(){}} class D extends R{} new D;'
 make: `sapi/cli/php' is up to date.
 
 Fatal error: Call to private R::__construct() from context '' in
 Command line code on line 1
 [EMAIL PROTECTED] PHP_5_0]$ cd ../PHP_5_1
 [EMAIL PROTECTED] PHP_5_1]$ php -r 'class R{private function
 __construct(){}} class D extends R{} new D;'
 make: `sapi/cli/php' is up to date.
 
 Fatal error: Call to private R::__construct() from context '' in
 Command line code on line 1
 [EMAIL PROTECTED] PHP_5_1]$ cd ../PHP_5_2
 [EMAIL PROTECTED] PHP_5_2]$ php -r 'class R{private function
 __construct(){}} class D extends R{} new D;'
 make: `sapi/cli/php' is up to date.
 
 Fatal error: Call to private R::__construct() from invalid context in
 Command line code on line 1
 [EMAIL PROTECTED] PHP_5_2]$ cd ../PHP_5_3
 [EMAIL PROTECTED] PHP_5_3]$ php -r 'class R{private function
 __construct(){}} class D extends R{} new D;'
 make: `sapi/cli/php' is up to date.
 
 Fatal error: Call to private R::__construct() from invalid context in
 Command line code on line 1
 [EMAIL PROTECTED] php-cvs]$ cd ../php-cvs
 [EMAIL PROTECTED] php-cvs]$ php -r 'class R{private function
 __construct(){}} class D extends R{} new D;'
 make: `sapi/cli/php' is up to date.
 
 Fatal error: Call to private R::__construct() from invalid context in
 Command line code on line 1
 
 Apparently all of 5.0, 5.1, 5.2, 5.3 and HEAD behave in the same way
 and issue a
 Fatal error as expected.
 
 Now your code uses self winthin class X which is derived from Y which
 has a
 private constructor. Let's see whether the ctor is illegally called in
 this
 example:
 
 [EMAIL PROTECTED] PHP_5_0]$ cd ../PHP_5_0
 [EMAIL PROTECTED] PHP_5_0]$ php -r 'class R{private function
 __construct(){echo R\n;}} class D extends R{static function
 f(){var_dump(new self);}} D::f();'
 make: `sapi/cli/php' is up to date.
 R
 object(D)#1 (0) {
 }
 [EMAIL PROTECTED] PHP_5_0]$ cd ../PHP_5_1
 [EMAIL PROTECTED] PHP_5_1]$ php -r 'class R{private function
 __construct(){echo R\n;}} class D extends R{static function
 f(){var_dump(new self);}} D::f();'
 make: `sapi/cli/php' is up to date.
 R
 object(D)#1 (0) {
 }
 [EMAIL PROTECTED] PHP_5_1]$ cd ../PHP_5_2
 [EMAIL PROTECTED] PHP_5_2]$ php -r 'class R{private function
 __construct(){echo R\n;}} class D extends R{static function
 f(){var_dump(new self);}} D::f();'
 make: `sapi/cli/php' is up to date.
 
 Fatal error: Call to private R::__construct() from context 'D' in
 Command line code on line 1
 
 So yes, there is a bug with the inheritance rules in older versions.
 
  i can remember that i asked a related question last year and someone
 told me
  it is ok so and its a know behavior.
  This change will ie. break ZF too. Any suggestions to this behavior?
 
 Fix the code by finding the correct way that works

Re: [PHP-DEV] PHP 5.3 bug or changed feature??

2007-12-09 Thread Marco Kaiser
This happens with many more functions. So i can verify this bug.

php -r echo md5(serialize(simplexml_load_file('example.xml'))) . PHP_EOL .
phpversion() . PHP_EOL;

Output PHP 5.2.5:
a6d7776fcb0e9c085b0d5972df792dac
5.2.5

Output PHP 5.3.0-dev (latest snap)
3e442cb7c8507c8941011735bb46e6de
5.3.0-dev

-- Marco

On Dec 9, 2007 1:22 PM, Rob Richards [EMAIL PROTECTED] wrote:

 Hi Frank,

 Frank M. Kromann wrote:
  Hello Everyon,
 
  Casting a SimpleXML object to an array gives different results in PHP
  5.2.5 and PHP 5.3-dev.
 
 This is due to the implementation of the get_debug_info handler merged
 from HEAD.
 The same result happens when calling get_object_vars on a
 SimpleXMLElement object.

 Marcus, was it intended to only include @attributes with print_r/var_dump?

 Rob
  Source:
 
  $xml = simplexml_load_file(sample.xml);
 
  foreach($xml-column as $column) {
  var_dump($column);
  var_dump((array)$column);
  }
 
  sample.xml
 
  ?xml version=1.0?
  cpdata
  column name=ENTERTAINMENT
  modulecv/module
  moduleentsimp/module
  /column
  column name=SEAT CONTROL
  modulepp/module
  modulesc/module
  /column
  /cpdata
 
  PHP 5.2 output:
  object(SimpleXMLElement)#4 (2) {
[@attributes]=
array(1) {
  [name]=
  string(13) ENTERTAINMENT
}
[module]=
array(2) {
  [0]=
  string(2) cv
  [1]=
  string(7) entsimp
}
  }
  array(2) {
[@attributes]=
array(1) {
  [name]=
  string(13) ENTERTAINMENT
}
[module]=
array(2) {
  [0]=
  string(2) cv
  [1]=
  string(7) entsimp
}
  }
  object(SimpleXMLElement)#5 (2) {
[@attributes]=
array(1) {
  [name]=
  string(12) SEAT CONTROL
}
[module]=
array(2) {
  [0]=
  string(2) pp
  [1]=
  string(2) sc
}
  }
  array(2) {
[@attributes]=
array(1) {
  [name]=
  string(12) SEAT CONTROL
}
[module]=
array(2) {
  [0]=
  string(2) pp
  [1]=
  string(2) sc
}
  }
 
  PHP 5.3 output:
 
  object(SimpleXMLElement)#4 (2) {
[@attributes]=
array(1) {
  [name]=
  string(13) ENTERTAINMENT
}
[module]=
array(2) {
  [0]=
  string(2) cv
  [1]=
  string(7) entsimp
}
  }
  array(1) {
[module]=
array(2) {
  [0]=
  string(2) cv
  [1]=
  string(7) entsimp
}
  }
  object(SimpleXMLElement)#5 (2) {
[@attributes]=
array(1) {
  [name]=
  string(12) SEAT CONTROL
}
[module]=
array(2) {
  [0]=
  string(2) pp
  [1]=
  string(2) sc
}
  }
  array(1) {
[module]=
array(2) {
  [0]=
  string(2) pp
  [1]=
  string(2) sc
}
  }
 
  Not that the attributes are gone when SimpleXML objects are converted in
  PHP 5.3. Is this a bug or a feature change?
 
  - Frank
 
 

 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Marco Kaiser


Re: [PHP-DEV] PHP 5.3 bug or changed feature??

2007-12-08 Thread Marco Kaiser
Hi Frank,

please open a bugreport about this issue. This would start the internal
process of verifying this.

-- Marco

On Dec 7, 2007 11:09 PM, Frank M. Kromann [EMAIL PROTECTED] wrote:

 Hello Everyon,

 Casting a SimpleXML object to an array gives different results in PHP
 5.2.5 and PHP 5.3-dev.

 Source:

 $xml = simplexml_load_file(sample.xml);

 foreach($xml-column as $column) {
var_dump($column);
var_dump((array)$column);
 }

 sample.xml

 ?xml version=1.0?
 cpdata
column name=ENTERTAINMENT
modulecv/module
moduleentsimp/module
/column
column name=SEAT CONTROL
modulepp/module
modulesc/module
/column
 /cpdata

 PHP 5.2 output:
 object(SimpleXMLElement)#4 (2) {
  [@attributes]=
  array(1) {
[name]=
string(13) ENTERTAINMENT
  }
  [module]=
  array(2) {
[0]=
string(2) cv
[1]=
string(7) entsimp
  }
 }
 array(2) {
  [@attributes]=
  array(1) {
[name]=
string(13) ENTERTAINMENT
  }
  [module]=
  array(2) {
[0]=
string(2) cv
[1]=
string(7) entsimp
  }
 }
 object(SimpleXMLElement)#5 (2) {
  [@attributes]=
  array(1) {
[name]=
string(12) SEAT CONTROL
  }
  [module]=
  array(2) {
[0]=
string(2) pp
[1]=
string(2) sc
  }
 }
 array(2) {
  [@attributes]=
  array(1) {
[name]=
string(12) SEAT CONTROL
  }
  [module]=
  array(2) {
[0]=
string(2) pp
[1]=
string(2) sc
  }
 }

 PHP 5.3 output:

 object(SimpleXMLElement)#4 (2) {
  [@attributes]=
  array(1) {
[name]=
string(13) ENTERTAINMENT
  }
  [module]=
  array(2) {
[0]=
string(2) cv
[1]=
string(7) entsimp
  }
 }
 array(1) {
  [module]=
  array(2) {
[0]=
string(2) cv
[1]=
string(7) entsimp
  }
 }
 object(SimpleXMLElement)#5 (2) {
  [@attributes]=
  array(1) {
[name]=
string(12) SEAT CONTROL
  }
  [module]=
  array(2) {
[0]=
string(2) pp
[1]=
string(2) sc
  }
 }
 array(1) {
  [module]=
  array(2) {
[0]=
string(2) pp
[1]=
string(2) sc
  }
 }

 Not that the attributes are gone when SimpleXML objects are converted in
 PHP 5.3. Is this a bug or a feature change?

 - Frank

 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Marco Kaiser


[PHP-DEV] private properties ....

2007-11-30 Thread Marco Kaiser
Hi List,

?php
error_reporting(E_ALL);

class aaa {
protected $_parent = null;
private $_value = 0;

public function setValue($value) {
$this-_value = $value;
}

public function getValue) {
return $this-_value;
}

public function setParent( $oParent ) {
$this-_parent = $oParent;
}

public function showParentValue() {
return $this-_parent-_value;
}
}

$aa = new aaa();
$aa-setValue(500);

$bb = new aaa();
$bb-setParent($aa);

echo $bb-showParentValue() . PHP_EOL;

?

The code above shows me a feature thats bypass my class design. :)
With this code it is possible to access the private class property _value
from $aa.
Output: 500

If i us a other class like :

class cc 
{
private $_value = 'foo';
}

$aa = new cc();

$bb = new aaa();
$bb-setParent($aa);
echo $bb-showParentValue() . PHP_EOL;

i get an error that tells me cc:$_value is private and could not be
accessed.
Thats ok.

But with this change i cant overload or change my property in any way.

class cc extends aaa
{
private $_value = 'foo';
}

$aa = new cc();

$bb = new aaa();
$bb-setParent($aa);
echo $bb-showParentValue() . PHP_EOL;
echo $aa-getValue() . PHP_EOL;

the output is:
0
0

Thats a bit strange to me because i expected a different behavior.

Conclusion:
1. Why i can access a private property from a different class instance
(name) but same type ?
$aa and $bb are instances of aaa but not the same.
2. This doesnt works if cc is a own class with same property name (ie.
interface or something like this)
3. Is it a bug that i can't use same property name in my child class?
(normaly the parent property isnt visible to the child)
cc extends aaa. 

Thats just some questions :)

-- Marco

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DEV] question regarding type hinting parameters of php functions (array_slice)

2007-11-28 Thread Marco Kaiser
Hi Dirk,

 When calling
 array_slice($array, 0, (float)2);
 the resulting array is EMPTY.
 When using the right type
 array_slice($array, 0, (int)2);
 it works as expected.

i think this should print a warning like other array functions.
But i looked into the src and this looks more like a casting bug inside this
function.

$input = array('a', 'b', 'c', 'd', 'e');
var_dump(array_slice($input, 1, 1));
var_dump(array_slice($input, 1, 1));
var_dump(array_slice($input, 1, (FLOAT)1));
var_dump(array_slice($input, 1, 1.0));

output:
array(1) {
  [0]=
  string(1) b
}
array(1) {
  [0]=
  string(1) b
}
array(0) {
}
array(0) {
}

So i think the float value isnt correct casted as int value here. Maybe
someone else
can proof this.

-- Marco

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DEV] late static binding php6

2007-11-23 Thread Marco Kaiser
Hi Marcus,

ahh now i know whats my thinking problem. :) the new introduced function
get_called_class() function gives me the
information how to work around my problem. :) static isnt really required.
:)


-- Marco

 -Original Message-
 From: Marcus Boerger [mailto:[EMAIL PROTECTED]
 Sent: Friday, November 23, 2007 12:23 PM
 To: Richard Quadling
 Cc: Marco Kaiser; PHP Developers Mailing List
 Subject: Re: [PHP-DEV] late static binding php6
 
 Hello Richard,
 
   that kind of stuff is the reason we added LSB. There is only one tiny
 thing I am not to happy about. You do not at all have to declare static
 $instance. Simply because you never use it. And for that reason you
 guys
 have your code worng. Use the following snippet for verification:
 var_dump($u=foo::getInstance());
 var_dump($v=bar::getInstance());
 var_dump($w=foo::getInstance());
 var_dump($x=bar::getInstance());
 var_dump(array($u,$v,$w,$x));
 
 When you want to have a factory of singletons that can create one
 single
 member of every derived class than you need to add an array to store
 those
 inside the abstract base class. That also allows to make that member
 private and thereby disallowing any derived class to interfere with the
 static member and get rid of them to overthrow the singleton
 limitation...
 You also have no need for the instanceof operation with the array. See
 here:
 
 ?php
 abstract class singleton
 {
 static private $instances = array();
 static final public function getInstance()
 {
 $caller = get_called_class();
 if (!isset(self::$instances[$caller])) {
 self::$instances[$caller] = new $caller;
 }
 return self::$instances[$caller];
 }
 }
 
 class foo extends singleton {
 }
 
 class bar extends singleton {
 }
 
 var_dump($u=foo::getInstance());
 var_dump($v=bar::getInstance());
 var_dump($w=foo::getInstance());
 var_dump($x=bar::getInstance());
 var_dump(array($u,$v,$w,$x));
 ?
 
 Friday, November 23, 2007, 10:21:51 AM, you wrote:
 
  On 23/11/2007, Richard Quadling [EMAIL PROTECTED] wrote:
  On 22/11/2007, Marco Kaiser [EMAIL PROTECTED] wrote:
   Hi again,
  
   to explain the main idea a bit more, the code below work and moves
 the
   main getInstance function from the class and its possible to
 abstract
   this.
   it would be cool to get the protected property also into the
 abstract
   class. Any idea or maybe a solution in the near future?
  
   ?php
   abstract class singleton
   {
   static public function getInstance()
   {
   $caller = get_called_class();
   if (!static::$_instance instanceof $caller) {
   static::$_instance = new $caller;
   }
  
   return static::$_instance;
   }
   }
  
   class foo extends singleton {
   static protected $_instance = null;
   }
  
   class bar extends singleton {
   static protected $_instance = null;
   }
  
   var_dump(foo::getInstance());
   var_dump(bar::getInstance());
   var_dump(foo::getInstance());
   var_dump(bar::getInstance());
   ?
  
   On Nov 22, 2007 9:29 PM, Marco Kaiser [EMAIL PROTECTED]
 wrote:
Hi List,
   
just to drop my note here, i asked (i think) 2 years ago for
 such a
feature to automate my singleton pattern. Not with late static
bindings this is possible.
   
?php
class singleton
{
static protected $_instance = null;
   
static public function getInstance()
{
$caller = get_called_class();
if (!static::$_instance instanceof $caller) {
static::$_instance = new $caller;
}
   
return static::$_instance;
}
}
   
class foo extends singleton
{
}
   
var_dump(foo::getInstance());
var_dump(foo::getInstance());
?
   
i think this will also drop much redundant code from some
 frameworks.
So this is one of my examples that helps much.
   
   
--
Marco Kaiser
   
  
  
  
   --
   Marco Kaiser
 
  ?php
  abstract class singleton
  {
 static protected $_instance = null;
 static public function getInstance()
 {
 $caller = get_called_class();
 if (!static::$_instance instanceof $caller) {
 static::$_instance = new $caller;
 }
 
 return static::$_instance;
 }
  }
 
  class foo extends singleton {
  }
 
  class bar extends singleton {
  }
 
  var_dump(foo::getInstance());
  var_dump(bar::getInstance());
  var_dump(foo::getInstance());
  var_dump(bar::getInstance());
  ?
 
  returns ...
 
  object(foo)#1 (0) {
  }
  object(bar)#2 (0) {
  }
  object(foo)#1 (0) {
  }
  object(bar)#2 (0) {
  }
 
  in PHP 5.3.0-dev (cli) (built: Nov 20 2007 08:19:12)
 
  I think this is great! Well done everyone. Unless I've completely
  missed the point.
 
  Also, you can

RE: [PHP-DEV] late static binding php6

2007-11-23 Thread Marco Kaiser
Hi Richard,

the problem is this:

?php
abstract class singleton
{
static protected $_instance;

static final public function getInstance()
{
$caller = get_called_class();
if (!static::$_instance instanceof $caller) {
echo NEW INSTANCE\n;
static::$_instance = new $caller;
}

return static::$_instance;
}
}

class foo extends singleton {
static protected $_instance;
}

class bar extends singleton {
static protected $_instance;
}

var_dump(foo::getInstance());
var_dump(bar::getInstance());
var_dump(foo::getInstance());
var_dump(bar::getInstance());
?

NEW INSTANCE
object(foo)#1 (0) {
}
NEW INSTANCE
object(bar)#2 (0) {
}
object(foo)#1 (0) {
}
object(bar)#2 (0) {
}

This means i just called once the constructor for the singleton abstract for 
every main class (foo, bar)
But if you remove the static member $_instance from the foo and bar class you 
get this result:

NEW INSTANCE
object(foo)#1 (0) {
}
NEW INSTANCE
object(bar)#2 (0) {
}
NEW INSTANCE
object(foo)#1 (0) {
}
NEW INSTANCE
object(bar)#2 (0) {
}

You see that the constructor is called every time if you use more than 1 
singleton class during script execution.
The problem is that the property isnt really inherited by the foo and bar class.

My idea or a possible solution would be to allow the definition of correct 
inheritance of the $_instance property or
to show me a way to set a static property dynamicly in the caller class.
Maybe Andi or Markus can explain this a bit more why this isnt possible. :)

-- Marco

 -Original Message-
 From: Richard Quadling [mailto:[EMAIL PROTECTED]
 Sent: Friday, November 23, 2007 10:22 AM
 To: Marco Kaiser
 Cc: PHP Developers Mailing List
 Subject: Re: [PHP-DEV] late static binding php6
 
 On 23/11/2007, Richard Quadling [EMAIL PROTECTED] wrote:
  On 22/11/2007, Marco Kaiser [EMAIL PROTECTED] wrote:
   Hi again,
  
   to explain the main idea a bit more, the code below work and moves
 the
   main getInstance function from the class and its possible to
 abstract
   this.
   it would be cool to get the protected property also into the
 abstract
   class. Any idea or maybe a solution in the near future?
  
   ?php
   abstract class singleton
   {
   static public function getInstance()
   {
   $caller = get_called_class();
   if (!static::$_instance instanceof $caller) {
   static::$_instance = new $caller;
   }
  
   return static::$_instance;
   }
   }
  
   class foo extends singleton {
   static protected $_instance = null;
   }
  
   class bar extends singleton {
   static protected $_instance = null;
   }
  
   var_dump(foo::getInstance());
   var_dump(bar::getInstance());
   var_dump(foo::getInstance());
   var_dump(bar::getInstance());
   ?
  
   On Nov 22, 2007 9:29 PM, Marco Kaiser [EMAIL PROTECTED]
 wrote:
Hi List,
   
just to drop my note here, i asked (i think) 2 years ago for such
 a
feature to automate my singleton pattern. Not with late static
bindings this is possible.
   
?php
class singleton
{
static protected $_instance = null;
   
static public function getInstance()
{
$caller = get_called_class();
if (!static::$_instance instanceof $caller) {
static::$_instance = new $caller;
}
   
return static::$_instance;
}
}
   
class foo extends singleton
{
}
   
var_dump(foo::getInstance());
var_dump(foo::getInstance());
?
   
i think this will also drop much redundant code from some
 frameworks. :)
So this is one of my examples that helps much.
   
   
--
Marco Kaiser
   
  
  
  
   --
   Marco Kaiser
 
  ?php
  abstract class singleton
  {
 static protected $_instance = null;
 static public function getInstance()
 {
 $caller = get_called_class();
 if (!static::$_instance instanceof $caller) {
 static::$_instance = new $caller;
 }
 
 return static::$_instance;
 }
  }
 
  class foo extends singleton {
  }
 
  class bar extends singleton {
  }
 
  var_dump(foo::getInstance());
  var_dump(bar::getInstance());
  var_dump(foo::getInstance());
  var_dump(bar::getInstance());
  ?
 
  returns ...
 
  object(foo)#1 (0) {
  }
  object(bar)#2 (0) {
  }
  object(foo)#1 (0) {
  }
  object(bar)#2 (0) {
  }
 
  in PHP 5.3.0-dev (cli) (built: Nov 20 2007 08:19:12)
 
  I think this is great! Well done everyone. Unless I've completely
  missed the point.
 
 Also, you can make the getInstance() method final so it cannot be
 overridden in sub-classes...
 
 ?php
 abstract class singleton
 {
static protected $_instance = null;
static final public function getInstance()
{
$caller

Re: [PHP-DEV] late static binding php6

2007-11-22 Thread Marco Kaiser
Hi List,

just to drop my note here, i asked (i think) 2 years ago for such a
feature to automate my singleton pattern. Not with late static
bindings this is possible.

?php
class singleton
{
static protected $_instance = null;

static public function getInstance()
{
$caller = get_called_class();
if (!static::$_instance instanceof $caller) {
static::$_instance = new $caller;
}

return static::$_instance;
}
}

class foo extends singleton
{
}

var_dump(foo::getInstance());
var_dump(foo::getInstance());
?

i think this will also drop much redundant code from some frameworks. :)
So this is one of my examples that helps much.


-- 
Marco Kaiser

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] late static binding php6

2007-11-22 Thread Marco Kaiser
Hi again,

to explain the main idea a bit more, the code below work and moves the
main getInstance function from the class and its possible to abstract
this.
it would be cool to get the protected property also into the abstract
class. Any idea or maybe a solution in the near future?

?php
abstract class singleton
{
static public function getInstance()
{
$caller = get_called_class();
if (!static::$_instance instanceof $caller) {
static::$_instance = new $caller;
}

return static::$_instance;
}
}

class foo extends singleton {
static protected $_instance = null;
}

class bar extends singleton {
static protected $_instance = null;
}

var_dump(foo::getInstance());
var_dump(bar::getInstance());
var_dump(foo::getInstance());
var_dump(bar::getInstance());
?

On Nov 22, 2007 9:29 PM, Marco Kaiser [EMAIL PROTECTED] wrote:
 Hi List,

 just to drop my note here, i asked (i think) 2 years ago for such a
 feature to automate my singleton pattern. Not with late static
 bindings this is possible.

 ?php
 class singleton
 {
 static protected $_instance = null;

 static public function getInstance()
 {
 $caller = get_called_class();
 if (!static::$_instance instanceof $caller) {
 static::$_instance = new $caller;
 }

 return static::$_instance;
 }
 }

 class foo extends singleton
 {
 }

 var_dump(foo::getInstance());
 var_dump(foo::getInstance());
 ?

 i think this will also drop much redundant code from some frameworks. :)
 So this is one of my examples that helps much.


 --
 Marco Kaiser




-- 
Marco Kaiser

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] $var::$static

2007-05-26 Thread Marco Kaiser
Hi,

this doesnt work because static vars are bound to his class and are not
inherited by a child class.
maybe this would be work with php6 or a other 5.x version.
(Same behavior like the singleton pattern getInstance() abstract class
stuff)

-- Marco
 Hi all,

 I'd like to be able to do the following:


 ?php

 class Base {

 public static $var = 'hello';

 public function someFunc() {
 echo self::$var; // Currently maps to Base::$var
 echo $this::$var; // Should map to Child::$var
 }

 }

 class Child extends Base {

 public static $var = 'hello';

 }

 $class = 'Child';

 $obj = new $class(); // This works.

 echo $class::$var; // This doesn't. Should map to Child::$var


 ?


 ...in other words: I'd like to be able to access static class
 variables from inside an instance of the Base and/or Child classes.
 I'd also like to be able to access them dynamically.
 ($className::$variable)

 The only way to do this at the moment (to my knowledge at least) is to
 create functions in the Child class that returns its static variables.
 The downside of this is that those functions most likely will be very
 common (in my case they are) and should therefore belong in the base
 class. Hence: $this::$variable

 At the moment there is no way to access static variables from outside
 of the class dynamically. As a workaround for this I'm currently
 creating a temporary instance (new $type()) to access them dynamically
 with a __get() function in all the derived child classes.

 There are ways to do it with class constants and the constant
 functions. But it's not very elegant and class constants can't hold
 arrays and/or objects.

 I have no idea what the implications would be. Just thought it would
 be a nice addition to the language. :) Hope I didn't overlook some
 existing PHP feature that already allows me to do this. :|


 Cheers,

 Bart de Boer


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] dom strange behaviours

2007-05-16 Thread Marco Kaiser
hi,

looks like you have an problem or this has been fixed with php 5.2.2.
Or can you maybe explain what you expect?

my results are:

Current PHP version: 5.2.2

getting id
--
getAttribute('id'):
getAttribute('xml:id'):one
getAttributeNS('xml','id'):

getAttribute('at'):
getAttribute('xml:at'):one
getAttributeNS('xml','at'):

getting id
--
getAttribute('id'):
getAttribute('xml:id'):two
getAttributeNS('xml','id'):

getAttribute('at'):
getAttribute('xml:at'):two
getAttributeNS('xml','at'):

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Constant Parameters

2007-03-02 Thread Marco Kaiser
Hi Jakob,
 It would be nice if in PHP 6 using constant parameters for functions
 and methods would be possible. This feature is e.g. available in Java.

 function doSth (const A) {
 if (defined (A)) echo A is a constant;
 }

 doSth (foo);

 Cheers,
 Jay

This makes absolute no sense, why you want this?

-- Marco

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] 23 nothing is so as it seems, but why

2006-01-19 Thread Marco Kaiser
Today during a session i had a strange magic feature found in php.

?php
$a = 10;
echo ++$a + $a++;
?

this works perfect as expected. it returns 22.
but if i assign $a as a ref. to another variable it will be return 23.

?
$a = 10;
$b = $a;
echo ++$a + $a++;
?

this will gave me to 23
(used the $b to the pre post stuff)

?
$a = 10;
$b = $a;
echo ++$b + $b++;
?

this just happens if i have a ref. count to my var. WHY? :)

http://en.wikipedia.org/wiki/23_%28film%29

--
Marco Kaiser


Re: [PHP-DEV] 23 nothing is so as it seems, but why

2006-01-19 Thread Marco Kaiser
Hmm yes i know this,
but its very interesting for me to see how php internaly handles ++$a with a
pointer.
Now i understand it :)

-- Marco

2006/1/19, Marcus Boerger [EMAIL PROTECTED]:

 Hello Marco,

   though Hartmut is perfectly correct in his statement here's what
 happens:

 $a = 10; // 10
 ++$a // 11
 $a + $a  // 22
 $a++ // 23

 Thursday, January 19, 2006, 5:41:17 PM, you wrote:

  Today during a session i had a strange magic feature found in php.

  ?php
  $a = 10;
  echo ++$a + $a++;
 ?

 just to verfiy echo $a after your echo line, it will show 12

  this works perfect as expected. it returns 22.
  but if i assign $a as a ref. to another variable it will be return 23.

  ?
  $a = 10;
  $b = $a;
  echo ++$a + $a++;
 ?

  this will gave me to 23
  (used the $b to the pre post stuff)

  ?
  $a = 10;
  $b = $a;
  echo ++$b + $b++;
 ?

  this just happens if i have a ref. count to my var. WHY? :)

  http://en.wikipedia.org/wiki/23_%28film%29

  --
  Marco Kaiser



 Best regards,
 Marcus




--
Marco Kaiser


[PHP-DEV] Re: [PHP] why php not running ?

2005-12-02 Thread Marco Kaiser
Hi Mehmet,

http://bugs.php.net/bugs-generating-backtrace.php
this is your help to get a backtrace.

 hi Marco. (since being a newbie, please be more clear to me :p)
  sorry but dont know how to do it ? :(
  would u please explain how to provide a full backtrace of my core dumped
 php ?

--
Marco Kaiser

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: [PHP] php problem

2005-12-02 Thread Marco Kaiser
Hi,

1st reply all please :)
2nd how should we help you if you can't tell us when or where the
problem happens.
Just to say FF FE will be displayed randomly is not usefull. Please
provide more informations or a demo site with .phps files to track the
problem or take a look at the source.

 it could be difficult because i don't know where the problem is.
 It happen when i visit 3-4 page that include different php into index.php
 so is difficult to backtrace the problem :(

--
Marco Kaiser

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Namespace poll: Presumably final numbers

2005-11-28 Thread Marco Kaiser
Hi,

just my notes. :)

Marco Kaiser |-| +1  | -2  | -2  | +2  | -1  | -2  | -2  | -2 
| -2  | -2  | -1  | -1  | -1  | -0  | +1  | +0  | +0  | -1  | -1  | -0
 |


--
Marco Kaiser

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: PHP 5.1 (Or How to break tousands of apps out there)

2005-11-25 Thread Marco Kaiser
Hi Rasmus,

 Nope, this change was in RC6:

 http://cvs.php.net/diff.php/php-src/ext/date/php_date.c?r1=1.43.2.20r2=1.43.2.21ty=u

 I missed it too, but then I don't use pear/Date anywhere.

thats nice to know, but RC's are Release Candidates and i understand
thats not allowed to implement new features in a release process. So
why does anyone changed something so important here without inform the
QA list about this? I what both lists, internal, and QA and i can't
check every commit to verify thats nothing changed that could break
BC.

I agree with Marcus that we should asap release a pl1 or 5.1.1.

--
Marco Kaiser

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php