php-general Digest 12 Feb 2012 12:07:17 -0000 Issue 7685

2012-02-12 Thread php-general-digest-help

php-general Digest 12 Feb 2012 12:07:17 - Issue 7685

Topics (messages 316571 through 316572):

Swiftlet is quite possibly the smallest MVC framework you'll ever use.
316571 by: Elbert F
316572 by: Simon Schick

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
I'm looking for constructive feedback on Swiftlet, a tiny MVC framework
that leverages the OO capabilities of PHP 5.3. It's intentionally
featureless and should familiar to those experienced with MVC. Any comments
on architecture, code and documentation quality are very welcome.

Source code and documentation: http://swiftlet.org
---End Message---
---BeginMessage---
Hi, Elbert

I've looked through the code and found it quite tiny. I like that.

Until now I found some things that I'd like to discuss with you:

In the class App you're doing all the stuff (routing, calling the
constructor aso) in the constructor. Would it not be better to have
separate functions for that? I like the way I learned from using Java: The
constructor is only for initializing the variables you need to execute the
other functions of this class.
Of course you can have a function that then calls all those small functions
and maybe directly return the output.

I dislike the way you treat with the model .. currently it gets the
controller, the view and the app itself. If you ask me the model only needs
some configuration. I cannot come up with an idea where you'd need more
than a connection-string and some additional settings. The model has
several methods to gather the data that has been requested and gives it
back. If you'd ask me, there's no need for interaction with the app,
controller or view.

I'd like to see an option for the router like the one I've seen in symfony2
... that was quite nice .. There you can define a regexp that should match
the called url, some variables that should be extracted from that and some
default-variables. It's quite hard to explain in the short term, but take a
look at their documentation:
http://symfony.com/doc/current/book/routing.html

I'd like you to create a small workflow what your framework is doing in
which order. Your framework to me looks like this image:
http://imageshack.us/f/52/mvcoriginal.png/ But I'd rethink if this
structure would give you more flexibility:
http://betterexplained.com/wp-content/uploads/rails/mvc-rails.png

I hope you got some input here you can work with. I'd like to hear your
feedback.

Bye
Simon


2012/2/12 Elbert F i...@elbertf.com

 I'm looking for constructive feedback on Swiftlet, a tiny MVC framework
 that leverages the OO capabilities of PHP 5.3. It's intentionally
 featureless and should familiar to those experienced with MVC. Any comments
 on architecture, code and documentation quality are very welcome.

 Source code and documentation: http://swiftlet.org

---End Message---


php-general Digest 13 Feb 2012 06:28:22 -0000 Issue 7686

2012-02-12 Thread php-general-digest-help

php-general Digest 13 Feb 2012 06:28:22 - Issue 7686

Topics (messages 316573 through 316578):

Variable number of arguments problem
316573 by: Tim Streater
316574 by: Stuart Dallas
316575 by: Tim Streater

Re: Swiftlet is quite possibly the smallest MVC framework you'll ever use.
316576 by: Elbert F
316577 by: Paul M Foster

questions about $_SERVER
316578 by: Rui Hu

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
I have a function defined thus:

function my_func ($arg1, $arg2, $arg3, $arg4, $arg5, $arg6)
 {

 // code here

 }

I call this with variously the first three arguments only, or all six, taking 
care that if I call it with fewer arguments then I don't try to acces $arg4, 
$arg5, or $arg6 (which is passed by reference, as is $arg1).

On my first attempt to execute this, I'm getting:

  Missing argument 4 for my_func(), called in /path/to/source/file1.php at line 
556 and defined
  in /path/to/source/file2.php at line 3

Is this because $arg6 is passed by reference? There is some reference to this 
in the docs and the user notes but it's a little unclear. Or is there another 
reason?

Thanks,

--
Cheers  --  Tim
---End Message---
---BeginMessage---
On 12 Feb 2012, at 18:51, Tim Streater wrote:

 I have a function defined thus:
 
 function my_func ($arg1, $arg2, $arg3, $arg4, $arg5, $arg6)
 {
 
 // code here
 
 }
 
 I call this with variously the first three arguments only, or all six, taking 
 care that if I call it with fewer arguments then I don't try to acces $arg4, 
 $arg5, or $arg6 (which is passed by reference, as is $arg1).
 
 On my first attempt to execute this, I'm getting:
 
  Missing argument 4 for my_func(), called in /path/to/source/file1.php at 
 line 556 and defined
  in /path/to/source/file2.php at line 3
 
 Is this because $arg6 is passed by reference? There is some reference to this 
 in the docs and the user notes but it's a little unclear. Or is there another 
 reason?

Optional arguments must be given a default value...

function my_func($arg1, $arg2, $arg3, $arg4 = null, $arg5 = null, $arg6 = 
null)

Note that passing a default value by reference was not supported prior to PHP5.

All the relevant details are here: http://php.net/functions.arguments

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
---End Message---
---BeginMessage---
On 12 Feb 2012 at 19:01, Stuart Dallas stu...@3ft9.com wrote: 

 Optional arguments must be given a default value...

 function my_func($arg1, $arg2, $arg3, $arg4 = null, $arg5 = null, $arg6 =
 null)

 Note that passing a default value by reference was not supported prior to
 PHP5.

 All the relevant details are here: http://php.net/functions.arguments

Thanks, I do see an example now, although it's not stated explicitly.

--
Cheers  --  Tim
---End Message---
---BeginMessage---
Hi Simon,

I think you're right that I may be abusing the constructor a bit. I'm going
to follow your suggestion and split it up into smaller functions. I'm also
thinking of moving the set_error_handler and spl_autoload_register
functions to index.php where Swiftlet is bootstrapped so they can be
changed.

You make another good point about the model; it's never supposed to access
the controller or view. I updated the code to reflect this. It should work
like your second
flowcharthttp://betterexplained.com/wp-content/uploads/rails/mvc-rails.png(perhaps
with the added concept of plugins, which can hook into anything).

Symfony's routing is nice, many smaller frameworks take a similar approach
(e.g. Sinatra http://www.sinatrarb.com/ and ToroPHP http://toroweb.org/).
However, I like the fact that Swiftlet requires no configuration. Just drop
in your class and it works. The file structure and classes already do a
good job describing themselves.

Excellent feedback, thanks!

Elbert



On Sun, Feb 12, 2012 at 10:53 PM, Simon Schick
simonsimc...@googlemail.comwrote:

 Hi, Elbert

 I've looked through the code and found it quite tiny I like that.

 Until now I found some things that I'd like to discuss with you:

 In the class App you're doing all the stuff (routing, calling the
 constructor aso) in the constructor. Would it not be better to have
 separate functions for that? I like the way I learned from using Java: The
 constructor is only for initializing the variables you need to execute the
 other functions of this class.
 Of course you can have a function that then calls all those small
 functions and maybe directly return the output.

 I dislike the way you treat with the model .. currently it gets the
 controller, the view and the app itself. If you ask me the model only needs
 some 

Re: [PHP] Swiftlet is quite possibly the smallest MVC framework you'll ever use.

2012-02-12 Thread Simon Schick
Hi, Elbert

I've looked through the code and found it quite tiny. I like that.

Until now I found some things that I'd like to discuss with you:

In the class App you're doing all the stuff (routing, calling the
constructor aso) in the constructor. Would it not be better to have
separate functions for that? I like the way I learned from using Java: The
constructor is only for initializing the variables you need to execute the
other functions of this class.
Of course you can have a function that then calls all those small functions
and maybe directly return the output.

I dislike the way you treat with the model .. currently it gets the
controller, the view and the app itself. If you ask me the model only needs
some configuration. I cannot come up with an idea where you'd need more
than a connection-string and some additional settings. The model has
several methods to gather the data that has been requested and gives it
back. If you'd ask me, there's no need for interaction with the app,
controller or view.

I'd like to see an option for the router like the one I've seen in symfony2
... that was quite nice .. There you can define a regexp that should match
the called url, some variables that should be extracted from that and some
default-variables. It's quite hard to explain in the short term, but take a
look at their documentation:
http://symfony.com/doc/current/book/routing.html

I'd like you to create a small workflow what your framework is doing in
which order. Your framework to me looks like this image:
http://imageshack.us/f/52/mvcoriginal.png/ But I'd rethink if this
structure would give you more flexibility:
http://betterexplained.com/wp-content/uploads/rails/mvc-rails.png

I hope you got some input here you can work with. I'd like to hear your
feedback.

Bye
Simon


2012/2/12 Elbert F i...@elbertf.com

 I'm looking for constructive feedback on Swiftlet, a tiny MVC framework
 that leverages the OO capabilities of PHP 5.3. It's intentionally
 featureless and should familiar to those experienced with MVC. Any comments
 on architecture, code and documentation quality are very welcome.

 Source code and documentation: http://swiftlet.org



[PHP] Variable number of arguments problem

2012-02-12 Thread Tim Streater
I have a function defined thus:

function my_func ($arg1, $arg2, $arg3, $arg4, $arg5, $arg6)
 {

 // code here

 }

I call this with variously the first three arguments only, or all six, taking 
care that if I call it with fewer arguments then I don't try to acces $arg4, 
$arg5, or $arg6 (which is passed by reference, as is $arg1).

On my first attempt to execute this, I'm getting:

  Missing argument 4 for my_func(), called in /path/to/source/file1.php at line 
556 and defined
  in /path/to/source/file2.php at line 3

Is this because $arg6 is passed by reference? There is some reference to this 
in the docs and the user notes but it's a little unclear. Or is there another 
reason?

Thanks,

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Variable number of arguments problem

2012-02-12 Thread Stuart Dallas
On 12 Feb 2012, at 18:51, Tim Streater wrote:

 I have a function defined thus:
 
 function my_func ($arg1, $arg2, $arg3, $arg4, $arg5, $arg6)
 {
 
 // code here
 
 }
 
 I call this with variously the first three arguments only, or all six, taking 
 care that if I call it with fewer arguments then I don't try to acces $arg4, 
 $arg5, or $arg6 (which is passed by reference, as is $arg1).
 
 On my first attempt to execute this, I'm getting:
 
  Missing argument 4 for my_func(), called in /path/to/source/file1.php at 
 line 556 and defined
  in /path/to/source/file2.php at line 3
 
 Is this because $arg6 is passed by reference? There is some reference to this 
 in the docs and the user notes but it's a little unclear. Or is there another 
 reason?

Optional arguments must be given a default value...

function my_func($arg1, $arg2, $arg3, $arg4 = null, $arg5 = null, $arg6 = 
null)

Note that passing a default value by reference was not supported prior to PHP5.

All the relevant details are here: http://php.net/functions.arguments

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Re: [PHP] Variable number of arguments problem

2012-02-12 Thread Tim Streater
On 12 Feb 2012 at 19:01, Stuart Dallas stu...@3ft9.com wrote: 

 Optional arguments must be given a default value...

 function my_func($arg1, $arg2, $arg3, $arg4 = null, $arg5 = null, $arg6 =
 null)

 Note that passing a default value by reference was not supported prior to
 PHP5.

 All the relevant details are here: http://php.net/functions.arguments

Thanks, I do see an example now, although it's not stated explicitly.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Swiftlet is quite possibly the smallest MVC framework you'll ever use.

2012-02-12 Thread Elbert F
Hi Simon,

I think you're right that I may be abusing the constructor a bit. I'm going
to follow your suggestion and split it up into smaller functions. I'm also
thinking of moving the set_error_handler and spl_autoload_register
functions to index.php where Swiftlet is bootstrapped so they can be
changed.

You make another good point about the model; it's never supposed to access
the controller or view. I updated the code to reflect this. It should work
like your second
flowcharthttp://betterexplained.com/wp-content/uploads/rails/mvc-rails.png(perhaps
with the added concept of plugins, which can hook into anything).

Symfony's routing is nice, many smaller frameworks take a similar approach
(e.g. Sinatra http://www.sinatrarb.com/ and ToroPHP http://toroweb.org/).
However, I like the fact that Swiftlet requires no configuration. Just drop
in your class and it works. The file structure and classes already do a
good job describing themselves.

Excellent feedback, thanks!

Elbert



On Sun, Feb 12, 2012 at 10:53 PM, Simon Schick
simonsimc...@googlemail.comwrote:

 Hi, Elbert

 I've looked through the code and found it quite tiny I like that.

 Until now I found some things that I'd like to discuss with you:

 In the class App you're doing all the stuff (routing, calling the
 constructor aso) in the constructor. Would it not be better to have
 separate functions for that? I like the way I learned from using Java: The
 constructor is only for initializing the variables you need to execute the
 other functions of this class.
 Of course you can have a function that then calls all those small
 functions and maybe directly return the output.

 I dislike the way you treat with the model .. currently it gets the
 controller, the view and the app itself. If you ask me the model only needs
 some configuration. I cannot come up with an idea where you'd need more
 than a connection-string and some additional settings. The model has
 several methods to gather the data that has been requested and gives it
 back. If you'd ask me, there's no need for interaction with the app,
 controller or view.

 I'd like to see an option for the router like the one I've seen in
 symfony2 ... that was quite nice .. There you can define a regexp that
 should match the called url, some variables that should be extracted from
 that and some default-variables. It's quite hard to explain in the short
 term, but take a look at their documentation:
 http://symfony.com/doc/current/book/routing.html

 I'd like you to create a small workflow what your framework is doing in
 which order. Your framework to me looks like this image:
 http://imageshack.us/f/52/mvcoriginal.png/ But I'd rethink if this
 structure would give you more flexibility:
 http://betterexplained.com/wp-content/uploads/rails/mvc-rails.png

 I hope you got some input here you can work with. I'd like to hear your
 feedback.

 Bye
 Simon


 2012/2/12 Elbert F i...@elbertf.com

 I'm looking for constructive feedback on Swiftlet, a tiny MVC framework
 that leverages the OO capabilities of PHP 5.3. It's intentionally
 featureless and should familiar to those experienced with MVC. Any
 comments
 on architecture, code and documentation quality are very welcome.

 Source code and documentation: http://swiftlet.org





Re: [PHP] Swiftlet is quite possibly the smallest MVC framework you'll ever use.

2012-02-12 Thread Paul M Foster
On Mon, Feb 13, 2012 at 09:24:38AM +1100, Elbert F wrote:

 Hi Simon,
 
 I think you're right that I may be abusing the constructor a bit. I'm going
 to follow your suggestion and split it up into smaller functions. I'm also
 thinking of moving the set_error_handler and spl_autoload_register
 functions to index.php where Swiftlet is bootstrapped so they can be
 changed.

I didn't look thoroughly at your code (though, if the respondent's
perceptions were correct, I'd have to agree with his prescriptions for
improvement). But I wanted to make a comment about autoloaders, since
you mentioned it.

My philosophy, since autoloading was introduced, was that it was a cool
way to avoid having a lot of complicated file inclusion calls all over
the place. Just tell the autoloader function where different types of
files were located, and then just instantiate classes as you like. Easy.

But I recently did some work for one of these companies with a million
file internally developed framework. And at the top of each file, they'd
include a require_once() (or similar) call for each of the files which
would be called if you needed to instantiate a class from any of those
files. So rather than putting all the magic in an autoloader function,
they'd simply include the file where they knew it would be needed.
(E.g., you know you're going to be calling your Date class in this file,
so you put a require_once() call to the file that contains it at the top
of this file.)

The more I've thought about it since then, the more I've considered it a
Good Thing(tm). It makes troubleshooting existing code a whole lot
easier. I don't have to wonder what the autoloader is doing or where the
files are, on which the current file depends. It sort of obviates the
autoloader stuff, but I'd rather do that than spend hours trying to
track down which file in which directory contains the class which paints
the screen blue or whatever. (Yes, I'm aware that require_once()
introduces some latency.)

Just something to consider.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] questions about $_SERVER

2012-02-12 Thread Michael Save
On Mon, Feb 13, 2012 at 5:28 PM, Rui Hu tchrb...@gmail.com wrote:
 hi,

 How PHP sets variables in $_SERVER, say, $DOCUMENT_ROOT? What should I know
 if I want to modify $_SERVER myself?

 Thanks!


 --
 Best regards,

 Rui Hu
 
 State Key Laboratory of Networking  Switching Technology
 Beijing University of Posts and Telecommunications(BUPT)
 MSN: tchrb...@gmail.com
 -

Rui,

$_SERVER is an associative array. You can access DOCUMENT_ROOT with
$_SERVER['DOCUMENT_ROOT']. It contains the document root directory
under which the current script is executing.

You can make changes to the $_SERVER array but it will have no effect
on PHP itself. I mean, you can change the value of
$_SERVER['DOCUMENT_ROOT'] to whatever you want at runtime, but of
course it will not actually change the current directory if that's
what you're after.

Thanks,
Michael

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Swiftlet is quite possibly the smallest MVC framework you'll ever use.

2012-02-12 Thread Elbert F
Hi Paul,

Swiftlet implements PSR-0, an unofficial standard that many of the
larger frameworks seem to be adopting. It simply maps namespaces to a
path, e.g. Foo\Bar\Baz translates to Foo/Bar/Baz.php. The advantage is
that you should be able to drop in third-party libraries which are
included by the same autoloader and without naming conflicts.

https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md

Elbert


  Hi Simon,
 
  I think you're right that I may be abusing the constructor a bit. I'm going
  to follow your suggestion and split it up into smaller functions. I'm also
  thinking of moving the set_error_handler and spl_autoload_register
  functions to index.php where Swiftlet is bootstrapped so they can be
  changed.

 I didn't look thoroughly at your code (though, if the respondent's
 perceptions were correct, I'd have to agree with his prescriptions for
 improvement). But I wanted to make a comment about autoloaders, since
 you mentioned it.

 My philosophy, since autoloading was introduced, was that it was a cool
 way to avoid having a lot of complicated file inclusion calls all over
 the place. Just tell the autoloader function where different types of
 files were located, and then just instantiate classes as you like. Easy.

 But I recently did some work for one of these companies with a million
 file internally developed framework. And at the top of each file, they'd
 include a require_once() (or similar) call for each of the files which
 would be called if you needed to instantiate a class from any of those
 files. So rather than putting all the magic in an autoloader function,
 they'd simply include the file where they knew it would be needed.
 (E.g., you know you're going to be calling your Date class in this file,
 so you put a require_once() call to the file that contains it at the top
 of this file.)

 The more I've thought about it since then, the more I've considered it a
 Good Thing(tm). It makes troubleshooting existing code a whole lot
 easier. I don't have to wonder what the autoloader is doing or where the
 files are, on which the current file depends. It sort of obviates the
 autoloader stuff, but I'd rather do that than spend hours trying to
 track down which file in which directory contains the class which paints
 the screen blue or whatever. (Yes, I'm aware that require_once()
 introduces some latency.)

 Just something to consider.

 Paul

 --
 Paul M. Foster
 http://noferblatz.com
 http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Swiftlet is quite possibly the smallest MVC framework you'll ever use.

2012-02-12 Thread Benjamin Hawkes-Lewis
On Sun, Feb 12, 2012 at 11:36 PM, Paul M Foster pa...@quillandmouse.com wrote:
 The more I've thought about it since then, the more I've considered it a
 Good Thing(tm). It makes troubleshooting existing code a whole lot
 easier. I don't have to wonder what the autoloader is doing or where the
 files are, on which the current file depends. It sort of obviates the
 autoloader stuff, but I'd rather do that than spend hours trying to
 track down which file in which directory contains the class which paints
 the screen blue or whatever.

Yeah, this is the sort of problem better handled by a tool than
switching away from autoloaders.

Exuberant Ctags is your friend.

--
Benjamin Hawkes-Lewis

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php