RE: [PHP-DEV] a way to fix the import issue

2007-10-04 Thread Dmitry Stogov
In your example :

?php
namespace Foo;
import Blah::Exception;
$a = new Exception;
?

new Exception refer to Blah::Exception and will fail if such class
doesn't exists.

import Blah::Exception creates an alias with short name Exception only
for current file (it doesn't creates Foo::Exception)

May be I didn't understood the question. :)

Thanks. Dmitry.

 -Original Message-
 From: Stanislav Malyshev [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, October 04, 2007 12:50 AM
 To: Greg Beaver; Dmitry Stogov
 Cc: php-dev; Benjamin Schulz
 Subject: Re: [PHP-DEV] a way to fix the import issue
 
 
  ?php
  namespace Foo;
  import Blah::Exception;
  $a = new Exception;
  ?
  
  should in fact be implicitly importing Blah::Exception as 
 if it were 
  Foo::Exception, rather than as ::Exception.  In other 
 words, I would 
  actually expect the above code to be equivalent to:
  
  ?php
  namespace Foo;
  import Blah::Exception as Foo::Exception;
  $a = new Foo::Exception;
  ?
 
 No, not really. It's equivalent to:
 ?
 $a = new Blah::Exception();
 ?
 
 There's no class named Foo::Exception and import does not create it. 
 However, I think I see what you were meaning - that new 
 Exception should 
 refer to Blah::Exception. I think it is true. Dmitry, could you look 
 into it? I.e. unqualified lookups inside namespace should also take 
 imports into account.
 
 -- 
 Stanislav Malyshev, Zend Software Architect
 [EMAIL PROTECTED]   http://www.zend.com/
 (408)253-8829   MSN: [EMAIL PROTECTED]
 
 -- 
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php
 

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



Re: [PHP-DEV] Class Posing

2007-10-04 Thread Timm Friebe

Hi,


  public function foo()
  {
  $bar= new Bar;

[...]

  }

When I want to test the foo() method, I want to stub out the usage of
the Bar class, for example, and have Bar::doSomething() return a
pre-configured value instead of performing its normal operation.


This is where you'd start refactoring the above sourcecode. I don't like 
this idea at all, because it really only helps you with testing legacy 
source you might not be able to or do not want to change (want to say: rare 
use-case IMO).


If you really need to intercept construction, you can still weave your 
interception functionality into sourcecode as you'd be doing in any AOP 
library. Simply write a stream wrapper for the file:// stream or add a 
filter to it to intercept all includes and / or requires your legacy code 
might contain and rewrite the sourcecode while loading, replacing new Foo 
by newinstance('Foo') - this might even be possible in a safe manner by 
using preg_replace.


- Timm 


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



[PHP-DEV] RE : [PHP-DEV] [PATCH] in_class_exists() for detecting __autoload() called by class_exists() and interface_exists()

2007-10-04 Thread P
 From: Stanislav Malyshev [mailto:[EMAIL PROTECTED] 

 But how would you know the class is missing? Maybe next 
 loader in chain 
 would find it.

IMO, the point, here, is that, if the requested class starts with 'PEAR2', by 
convention, this name space is reserved and cannot be resolved by another 
handler. So, it is legitimate to want the PEAR2 autoload handler to display a 
message explaining how to get the missing package. But I wouldn't attempt to 
enrich the interpreter's 'not found' message, I would instead just have the 
handler trigger a warning message. The user would just receive 2 messages: an 
'information' warning and a fatal error.

Regards

Francois

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



Re: [PHP-DEV] a way to fix the import issue

2007-10-04 Thread Gregory Beaver
Dmitry Stogov wrote:
 In your example :
 
 ?php
 namespace Foo;
 import Blah::Exception;
 $a = new Exception;
 ?
 
 new Exception refer to Blah::Exception and will fail if such class
 doesn't exists.
 
 import Blah::Exception creates an alias with short name Exception only
 for current file (it doesn't creates Foo::Exception)
 
 May be I didn't understood the question. :)

Yes, you do misunderstand I think :)

testme.php:
?php
namespace Blah;
class Exception extends ::Exception {}
?

test.php:
?php
namespace Foo;
include 'testme.php';
import Blah::Exception;
$a = new Exception;
?

result:
[EMAIL PROTECTED]:~/workspace/php5$ sapi/cli/php -n test.php

Fatal error: Import name 'Exception' conflicts with defined class in
/home/cellog/workspace/php5/test.php on line 4

This is because of this check:

if (zend_hash_exists(CG(class_table), lcname, Z_STRLEN_P(name)+1)) {
zend_error(E_COMPILE_ERROR, Import name '%s' conflicts with 
defined
class, Z_STRVAL_P(name));
}

we are comparing Exception to Exception in the class table, and so
we get a fatal error.  We should instead transparently import
Blah::Exception not as Exception but as Foo::Exception *only* for
the above comparison check.  In other words, import needs to honor
namespace when checking for class naming conflicts.

If you can create class Exception inside namespace Foo and refer to it
as Exception then import Blah::Exception should also allow referring
to Exception *if* Foo::Exception doesn't already exist.

Greg

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



Re: [PHP-DEV] [PATCH] in_class_exists() for detecting __autoload() called by class_exists() and interface_exists()

2007-10-04 Thread Benjamin Schulz

Hi,
What about __class_exists() and SPL_register_class_exists_handler()?  
One could suppose the classloader (the one that implements  
__autoload) knows if a class exists (as in: is registered within the  
classloader or the class-file exists) without loading it and maybe  
the class that calls class_exists() never uses it.


regards,
Benjamin

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



Re: [PHP-DEV] substr/array_slice in []

2007-10-04 Thread Andrei Zmievski
So it's okay to discuss implementation of esoteric features like class 
posing, but something as basic as a string/array slice operation still 
gets a knee-jerk reaction? Double standards my friends, double standards..


-Andrei

Stanislav Malyshev wrote:
Here's much better reason: PHP is not the kitchen sink of features and 
syntaxes. Not every cool idea belongs to core PHP. I am saying that this 
particular feature definitely doesn't, but it needs to be proven that it 
does. My opinion is that the same function is easily implemented by 
existing means so adding this syntax is redundant.


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



[PHP-DEV] how declare protected array property at internal class properly

2007-10-04 Thread Denis Gabaidulin
How can i do subj ?

I try make this with follwoing code:

declare prop:

zend_declare_property_null(ns_ce_ ## my_class, prop, strlen(prop),
, ZEND_ACC_PROTECTED TSRMLS_CC);


at constructor:

zval *prop;

/* init */
prop =  zend_read_property(Z_OBJCE_P(getThis()), getThis(), prop,
strlen(prop,), 1 TSRMLS_CC);

array_init(prop);


After building ext (with debug) i get following error:

Fatal error: Internal zval's can't be arrays, objects or resources

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



Re: [PHP-DEV] how declare protected array property at internal class properly

2007-10-04 Thread Michael Wallner
Denis Gabaidulin wrote:
 How can i do subj ?

 at constructor:
 
 zval *prop;
 
 /* init */
 prop =  zend_read_property(Z_OBJCE_P(getThis()), getThis(), prop,
 strlen(prop,), 1 TSRMLS_CC);
 
 array_init(prop);

zval *prop;
MAKE_STD_ZVAL(prop);
array_init(prop);
zend_update_property(Z_OBJCE_P(getThis()), getThis(),
ZEND_STRS(prop)-1, prop TSRMLS_CC);
zval_ptr_dtor(prop);

IIRC complex types for internal zvals was on some engine todo or--at
least--wish list...

Regards,
-- 
Michael

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



Re: [PHP-DEV] how declare protected array property at internal class properly

2007-10-04 Thread Denis Gabaidulin
On 10/5/07, Michael Wallner [EMAIL PROTECTED] wrote:

 zval *prop;
 MAKE_STD_ZVAL(prop);
 array_init(prop);
 zend_update_property(Z_OBJCE_P(getThis()), getThis(),
 ZEND_STRS(prop)-1, prop TSRMLS_CC);
 zval_ptr_dtor(prop);

 IIRC complex types for internal zvals was on some engine todo or--at
 least--wish list...

Good news...


 Regards,
 --
 Michael


Thanks a lot, Michael.

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



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



Re: [PHP-DEV] substr/array_slice in []

2007-10-04 Thread Larry Garfield
On Tuesday 02 October 2007, Alexey Zakhlestin wrote:
 On 10/1/07, Martin Alterisio [EMAIL PROTECTED] wrote:
  Sorry to bother, I have a few questions on this matter.
  How will this impact on the SPL ArrayAccess and related interfaces and
  objects?
  Will there be an interface to this functionality?
  If so, how will ranges be passed through to this interface?
  Will this be consistent with substr() and array_slice() if used with an
  ArrayAccess implementation?

 I guess it can be made to work with current ArrayAccess, but result
 will be quite slow. (it will need to query requested elements
 one-by-one and recombine those in array)

 But adding another interface can solve the problem. Ranges can be
 passed exactly the way they are passed to [] operator

 public function rangeGet($start, $length);
 public function rangeSet($start, $length, array $data);

Here's the question I see.  Right now, does an ArrayAccess object work with 
array_slice()?  If so, then [2, 5] syntax would be just some nice syntactic 
sugar.  If not, then it becomes a powerful new feature, and implementing it 
on normal arrays and strings becomes just a matter of consistent syntax.

Personaly I kinda like it, but I know I'm not the one coding it. :-)

-- 
Larry Garfield  AIM: LOLG42
[EMAIL PROTECTED]   ICQ: 6817012

If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it.  -- Thomas 
Jefferson

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



Re: [PHP-DEV] a way to fix the import issue

2007-10-04 Thread Gregory Beaver
Dmitry Stogov wrote:
 In your example :
 
 ?php
 namespace Foo;
 import Blah::Exception;
 $a = new Exception;
 ?
 
 new Exception refer to Blah::Exception and will fail if such class
 doesn't exists.
 
 import Blah::Exception creates an alias with short name Exception only
 for current file (it doesn't creates Foo::Exception)
 
 May be I didn't understood the question. :)

http://bugs.php.net/42859 has a further example

with patches for PHP 6 and PHP 5 in the report.

Greg

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



[PHP-DEV] Re: [PATCH] reserved words allowed as function/method names

2007-10-04 Thread Gregory Beaver
Patches added to http://bugs.php.net/28261, and I re-opened the bug.

Greg

Gregory Beaver wrote:
 Hi,
 
 I spent a while tonight tinkering with the parser to try to figure out
 how to allow it to use T_IMPORT as well as T_STRING for method names,
 and quickly came to the conclusion that this causes way more trouble
 than it is worth.  However, in a moment of inspiration, I realized that
 a minor change in the lexer would allow any reserved words for method
 names.  The patch is attached.  This patch allows all kinds of odd
 looking code that probably won't be used, but permanently guarantees
 that code written for PHP now will never conflict with future reserved
 words:
 
 ?php
 namespace testing;
 class Test {
 function array()
 {
 echo array\n;
 }
 function class()
 {
 echo class\n;
 }
 static function import()
 {
 echo import\n;
 }
 function new()
 {
 echo new\n;
 }
 $a = new Test;
 $a-array();
 $a-class();
 $a-new();
 Test::import();
 testing::Test::import();
 ?
 
 The patch does not allow reserved names for class names, interface
 names, functions, or for class constants.  This would be much harder to
 implement in the lexer, and in my experience collisions with reserved
 words most often happens with methods.
 
 The patch only allows methods to use reserved words, not functions, and
 causes a fatal error with this code:
 
 ?php
 function foreach($a)
 {
 }
 ?
 
 This prevents this wtf code, which would also produce a different (and
 non-intuitive) fatal error:
 
 ?php
 foreach (foreach() as $foreach) {foreach();}
 ?
 
 The patch is against PHP 5.3, and PHP 6
 
 Greg
 
 
 
 
 ? better_halt.patch.txt
 ? config.cli
 ? config.nice.nodebug
 ? err
 ? install-pear-nozlib.phar
 ? run-tests.oops.patch.txt
 ? smarter_lexer.patch.txt
 ? test-phar.sh
 ? test.phar
 ? testme.php
 ? zlib.patch
 ? Zend/tests/zend_function_name.phpt
 ? ext/gd/run-tests.php
 ? ext/gettext/run-tests.php
 ? ext/mysqli/run-tests.php
 ? ext/zip/run-tests.php
 ? ext/zlib/zlib_filter.c.2
 ? pear/scripts
 ? tests/lang/halt_compiler1.phpt
 ? tests/lang/halt_compiler2.phpt
 ? tests/lang/halt_compiler3.phpt
 ? tests/lang/halt_compiler4.phpt
 Index: run-tests.php
 ===
 RCS file: /repository/php-src/run-tests.php,v
 retrieving revision 1.226.2.37.2.35
 diff -u -r1.226.2.37.2.35 run-tests.php
 --- run-tests.php 14 Sep 2007 15:28:03 -  1.226.2.37.2.35
 +++ run-tests.php 3 Oct 2007 02:40:57 -
 @@ -1328,12 +1328,15 @@
   $raw_lines = explode(\n, $post);
  
   $request = '';
 + $started = false;
   foreach ($raw_lines as $line) {
   if (empty($env['CONTENT_TYPE'])  
 preg_match('/^Content-Type:(.*)/i', $line, $res)) {
   $env['CONTENT_TYPE'] = trim(str_replace(\r, 
 '', $res[1]));
   continue;
   }
 - $request .= $line . \n;
 + if ($started) $request .= \n;
 + $started = true;
 + $request .= $line;
   }
  
   $env['CONTENT_LENGTH'] = strlen($request);
 Index: Zend/zend_language_scanner.l
 ===
 RCS file: /repository/ZendEngine2/zend_language_scanner.l,v
 retrieving revision 1.131.2.11.2.13.2.1
 diff -u -r1.131.2.11.2.13.2.1 zend_language_scanner.l
 --- Zend/zend_language_scanner.l  28 Sep 2007 19:52:50 -  
 1.131.2.11.2.13.2.1
 +++ Zend/zend_language_scanner.l  3 Oct 2007 02:41:02 -
 @@ -978,6 +978,9 @@
  }
  
  ST_IN_SCRIPTINGfunction {
 + if (CG(active_class_entry)) {
 + yy_push_state(ST_LOOKING_FOR_PROPERTY TSRMLS_CC);
 + }
   return T_FUNCTION;
  }
  
 @@ -1118,6 +1121,14 @@
   return T_OBJECT_OPERATOR;
  }
  
 +ST_LOOKING_FOR_PROPERTY{WHITESPACE} {
 + zendlval-value.str.val = yytext; /* no copying - intentional */
 + zendlval-value.str.len = yyleng;
 + zendlval-type = IS_STRING;
 + HANDLE_NEWLINES(yytext, yyleng);
 + return T_WHITESPACE;
 +}
 +
  ST_LOOKING_FOR_PROPERTY{LABEL} {
   yy_pop_state(TSRMLS_C);
   zend_copy_value(zendlval, yytext, yyleng);
 @@ -1131,6 +1142,7 @@
  }
  
  ST_IN_SCRIPTING:: {
 + yy_push_state(ST_LOOKING_FOR_PROPERTY TSRMLS_CC);
   return T_PAAMAYIM_NEKUDOTAYIM;
  }
  
 
 
 
 
 Index: Zend/zend_language_scanner.l
 ===
 RCS file: /repository/ZendEngine2/zend_language_scanner.l,v
 retrieving revision 1.170
 diff -u -r1.170 zend_language_scanner.l
 --- Zend/zend_language_scanner.l  9 Sep 2007 22:49:31 -   1.170
 +++ Zend/zend_language_scanner.l  3 Oct 2007 02:42:31 -
 @@ -1483,6 +1483,9 @@
  }
  
  ST_IN_SCRIPTINGfunction {
 + 

[PHP-DEV] get_namespace()

2007-10-04 Thread Michael Gauthier
With PHP 5.3 will there be a get_namespace($object) function equivalent
to get_class($object)?

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



Re: [PHP-DEV] substr/array_slice in []

2007-10-04 Thread Alexey Zakhlestin
On 10/5/07, Larry Garfield [EMAIL PROTECTED] wrote:

 Here's the question I see.  Right now, does an ArrayAccess object work with
 array_slice()?  If so, then [2, 5] syntax would be just some nice syntactic
 sugar.  If not, then it becomes a powerful new feature, and implementing it
 on normal arrays and strings becomes just a matter of consistent syntax.

currently, array_slice doesn't work with ArrayAccess


-- 
Alexey Zakhlestin
http://blog.milkfarmsoft.com/

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