php-general Digest 25 Aug 2012 21:01:00 -0000 Issue 7936

Topics (messages 318835 through 318848):

Re: Using PEAR and PHP
        318835 by: Carlos Medina

Re: set up mass virtual hosting with apache/nginx and PHP ... best practice2012?
        318836 by: Carlos Medina
        318838 by: Matijn Woudt
        318839 by: Duken Marga
        318845 by: D. Dante Lorenso
        318847 by: D. Dante Lorenso

Re: away from Fedora linux for a while and now this ...HELP
        318837 by: Matijn Woudt
        318840 by: Sebastian Krebs

redefine a define ...
        318841 by: Lester Caine
        318842 by: Adam Richardson
        318843 by: Matijn Woudt
        318844 by: Matt Neimeyer
        318846 by: Ashley Sheridan
        318848 by: Lester Caine

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


----------------------------------------------------------------------
--- Begin Message ---
Hi Suraj,
take my advice: read the Manual!

Greets

Carlos


Am 23.08.2012 19:42, schrieb Suraj Shah:
> Hi.
> 
> I am currently working on a website which uses PHP as an integral programming 
> language as part of it.
> 
> I am trying to replicate the website’s contents from one ftp server to 
> another but am encountering serious issues in doing so. I’ve spent two days 
> trying to find out the reasons and now think its down to the PEAR 
> installation.
> 
> This is therefore a question on if I want to transfer a website from one 
> domain to another, then do I need to install PEAR and re-configure all the 
> files? At the moment, all I can see within the ftp client regarding PEAR are 
> the ‘Mail’ and ‘Mail_Mime’ components.
> 
> I am new to this so any help on this would be great.
> 
> Many thanks
> 
> Suraj
> 
> 
> Suraj Shah
> Online Marketing Executive
> 26 Throgmorton Street | London | EC2N 2AN
> t: 020 7826 9031
> e: su...@aifa.net
> w: www.aifa.net
> 


--- End Message ---
--- Begin Message ---
Hi,

Read the Apache and PHP Documentation, if you have any questions after
this. write again...


Greets

Carlos



Am 22.08.2012 01:26, schrieb D. Dante Lorenso:
> All,
> 
> I need to set up a server to enable 5,000 students to have web hosting
> provided by the school with PHP and MySQL support.  I'm trying to figure
> out what is the best way to do this.
> 
> We have Active Directory and are using Centrify to authenticate
> usernames and passwords on our Linux servers.  I am imagining it would
> be great if we use something like ExecCGI to ensure that PHP runs as the
> user that owns the files.  We would then provide FTP access to the files
> and FTP would authenticate against Active Directory making sure to set
> the proper user/group on files when uploaded.
> 
> I see that PHP-FPM exists: http://php-fpm.org  and it claims "Ability to
> start workers with different uid/gid/chroot/environment and different
> php.ini (replaces safe_mode)" which is exactly what I'm looking for.  It
> also claims "PHP-FPM is now included in PHP core as of PHP 5.3.3." so
> that's good.
> 
> I also read about the greatness that is NGinX: http://nginx.org though I
> don't know if I can use it because I think I also need to use .htaccess
> files.  I need a way for students to be able to password protect their
> directories and files.  If there's another way using NGinX or Apache,
> that's good too.  I know of no other way.
> 
> Here is an interesting article from 2009:
> http://www.howtoforge.com/how-to-set-up-mass-virtualhosting-with-apache2-mod_rewrite-mod_userdir-mod_suexec-on-centos-5.3
> 
> 
> That uses mod_rewrite to attempt something like what I'm trying to do
> ... and then, Apache has mod_vhost_alias:
> http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html
> 
> So, I see a lot of information out there.  Apache, NginX, ExecCGI,
> FastCGI, mod_vhost_alias, mod_rewrite, SuExec, mod_userdir.  I suspect
> some of these methods are old and out of date.
> 
> In my ideal situation:
> 
>  - users would be created in AD and would exist on the OS
> 
>  - student domain names would look like:
>     http://<username>.student.school.edu/ - OR -
>     http://student.school.edu/<username>/
> 
>  - file directories would look like:
>     /mnt/somedir/<username>/docroot
> 
>  - students would be able to create PHP applications executed with
>     their own permissions
> 
>  - I would be able to configure all 5,000 accounts with a single
>     configuration (1 virtual host rule?)
> 
> Do you know what the "best practices" are for now ... here in 2012?
> 
> -- Dante
> 


--- End Message ---
--- Begin Message ---
On Sat, Aug 25, 2012 at 11:09 AM, Carlos Medina <i...@simply-networks.de> wrote:
> Hi,
>
> Read the Apache and PHP Documentation, if you have any questions after
> this. write again...
>
>
> Greets
>
> Carlos
>

OT:
Carlos, There's no need to write useless replies like this (also on
other topics). I'm pretty sure there's no answer to his question in
the manual. He explicitly asks for help and experiences for PHP with
~5.000 virtual hosts.
Also, you should bottom post on this, and probably any, mailing list.

>
> Am 22.08.2012 01:26, schrieb D. Dante Lorenso:
>> All,
>>
>> I need to set up a server to enable 5,000 students to have web hosting
>> provided by the school with PHP and MySQL support.  I'm trying to figure
>> out what is the best way to do this.
>>
>> We have Active Directory and are using Centrify to authenticate
>> usernames and passwords on our Linux servers.  I am imagining it would
>> be great if we use something like ExecCGI to ensure that PHP runs as the
>> user that owns the files.  We would then provide FTP access to the files
>> and FTP would authenticate against Active Directory making sure to set
>> the proper user/group on files when uploaded.
>>
>> I see that PHP-FPM exists: http://php-fpm.org  and it claims "Ability to
>> start workers with different uid/gid/chroot/environment and different
>> php.ini (replaces safe_mode)" which is exactly what I'm looking for.  It
>> also claims "PHP-FPM is now included in PHP core as of PHP 5.3.3." so
>> that's good.
>>
>> I also read about the greatness that is NGinX: http://nginx.org though I
>> don't know if I can use it because I think I also need to use .htaccess
>> files.  I need a way for students to be able to password protect their
>> directories and files.  If there's another way using NGinX or Apache,
>> that's good too.  I know of no other way.
>>
>> Here is an interesting article from 2009:
>> http://www.howtoforge.com/how-to-set-up-mass-virtualhosting-with-apache2-mod_rewrite-mod_userdir-mod_suexec-on-centos-5.3
>>
>>
>> That uses mod_rewrite to attempt something like what I'm trying to do
>> ... and then, Apache has mod_vhost_alias:
>> http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html
>>
>> So, I see a lot of information out there.  Apache, NginX, ExecCGI,
>> FastCGI, mod_vhost_alias, mod_rewrite, SuExec, mod_userdir.  I suspect
>> some of these methods are old and out of date.
>>
>> In my ideal situation:
>>
>>  - users would be created in AD and would exist on the OS
>>
>>  - student domain names would look like:
>>     http://<username>.student.school.edu/ - OR -
>>     http://student.school.edu/<username>/
>>
>>  - file directories would look like:
>>     /mnt/somedir/<username>/docroot
>>
>>  - students would be able to create PHP applications executed with
>>     their own permissions
>>
>>  - I would be able to configure all 5,000 accounts with a single
>>     configuration (1 virtual host rule?)
>>
>> Do you know what the "best practices" are for now ... here in 2012?
>>
>> -- Dante
>>
>

Hi Dante,

Wouldn't it be much easier to use reseller packages like DirectAdmin
or cPanel? AFAIK it should be pretty easy to do the things above.

- Matijn

--- End Message ---
--- Begin Message ---
>From my experience to maintain many virtual host, I prefer use Apache + PHP
+ suPHP. I think this combination will be able to cover your ideal
situation above. But, I usually use authentication via shell user
(/etc/user). You must find tutorial or something that integrate Apache and
Active Directory (there are many out there).

suPHP is designed to replace suExec (default Apache mod). It will run a PHP
file as a user that own the files. There are no problem if you want to use
it for many user, because suPHP is designed for that. For user who will
uploade file, you can always use FTP to access their own file. Each user
can has their own .htaccess in their own directory and all the websites
will have one global rule in httpd.conf.

On Wed, Aug 22, 2012 at 6:26 AM, D. Dante Lorenso <da...@lorenso.com> wrote:

> All,
>
> I need to set up a server to enable 5,000 students to have web hosting
> provided by the school with PHP and MySQL support.  I'm trying to figure
> out what is the best way to do this.
>
> We have Active Directory and are using Centrify to authenticate usernames
> and passwords on our Linux servers.  I am imagining it would be great if we
> use something like ExecCGI to ensure that PHP runs as the user that owns
> the files.  We would then provide FTP access to the files and FTP would
> authenticate against Active Directory making sure to set the proper
> user/group on files when uploaded.
>
> I see that PHP-FPM exists: http://php-fpm.org  and it claims "Ability to
> start workers with different uid/gid/chroot/environment and different
> php.ini (replaces safe_mode)" which is exactly what I'm looking for.  It
> also claims "PHP-FPM is now included in PHP core as of PHP 5.3.3." so
> that's good.
>
> I also read about the greatness that is NGinX: http://nginx.org though I
> don't know if I can use it because I think I also need to use .htaccess
> files.  I need a way for students to be able to password protect their
> directories and files.  If there's another way using NGinX or Apache,
> that's good too.  I know of no other way.
>
> Here is an interesting article from 2009:
> http://www.howtoforge.com/how-**to-set-up-mass-virtualhosting-**
> with-apache2-mod_rewrite-mod_**userdir-mod_suexec-on-centos-**5.3<http://www.howtoforge.com/how-to-set-up-mass-virtualhosting-with-apache2-mod_rewrite-mod_userdir-mod_suexec-on-centos-5.3>
>
> That uses mod_rewrite to attempt something like what I'm trying to do ...
> and then, Apache has mod_vhost_alias:
> http://httpd.apache.org/docs/**2.2/mod/mod_vhost_alias.html<http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html>
>
> So, I see a lot of information out there.  Apache, NginX, ExecCGI,
> FastCGI, mod_vhost_alias, mod_rewrite, SuExec, mod_userdir.  I suspect some
> of these methods are old and out of date.
>
> In my ideal situation:
>
>  - users would be created in AD and would exist on the OS
>
>  - student domain names would look like:
>         http://<username>.student.**school.edu/<http://student.school.edu/>- 
> OR -
>         http://student.school.edu/<**username>/
>
>  - file directories would look like:
>         /mnt/somedir/<username>/**docroot
>
>  - students would be able to create PHP applications executed with
>         their own permissions
>
>  - I would be able to configure all 5,000 accounts with a single
>         configuration (1 virtual host rule?)
>
> Do you know what the "best practices" are for now ... here in 2012?
>
> -- Dante
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Duken Marga

--- End Message ---
--- Begin Message ---
On 8/25/12 6:11 AM, Matijn Woudt wrote:
Hi Dante,

Wouldn't it be much easier to use reseller packages like DirectAdmin
or cPanel? AFAIK it should be pretty easy to do the things above.

I'm considering that as well. In the end, I really only want 3 features, however:

 - ftp access to files
 - mysql database
 - apache/php support

Look at DirectAdmin features:
http://www.directadmin.com/features.html

Looks like 80-90% of that is not needed. I want to manage my users through Active Directory, and just enable or disable the 3 services I listed above.

I recently tested ISP Manager. Their trial license couldn't even be installed without a public IP address! I don't want to get into these games. Just some simple, clean, open source solutions, please :-)

Also, I intend to make this solution scalable. I have 2 HA load balancers that will distribute the web load across multiple web servers. Licensing starts to get expensive when you begin to think clusters or clouds. I want to scale without additional licensing costs.

I'll install DirectAdmin and cPanel now that you recommend them, however, to make sure I don't actually want them :-)

-- Dante


--- End Message ---
--- Begin Message ---
On 8/25/12 7:50 AM, Duken Marga wrote:
 >From my experience to maintain many virtual host, I prefer use Apache
+ PHP + suPHP. I think this combination will be able to cover your ideal
situation above. But, I usually use authentication via shell user
(/etc/user). You must find tutorial or something that integrate Apache
and Active Directory (there are many out there).

suPHP is designed to replace suExec (default Apache mod). It will run a
PHP file as a user that own the files. There are no problem if you want
to use it for many user, because suPHP is designed for that. For user
who will uploade file, you can always use FTP to access their own file.
Each user can has their own .htaccess in their own directory and all the
websites will have one global rule in httpd.conf.

Using VirtualDocumentRoot, I was able to create a virtual host defined like this:

<VirtualHost *:80>
ServerName student.sampledomain.edu
ServerAlias *.student.sampledomain.edu

DocumentRoot /mnt/web/student.sampledomain.edu/docroot
UseCanonicalName Off
VirtualDocumentRoot /mnt/userwww/%-4+

ErrorLog "|/usr/bin/logger -p local6.notice -t 'error-student'"
CustomLog "|/usr/bin/logger -p local6.notice -t 'access-student'" full
</VirtualHost>

That maps domain names like <username>.student.sampledomain.edu to directories in the /mnt/userwww/<username> directory. That gets me close, but isn't handling PHP yet. I think Apache also runs as 'apache' user when reading all the files, so users must chmod their files world readable still for this to work.

You reference "suPHP" as the way to go. The problem I have with that is this website:
http://www.suphp.org/Home.html

Looks like the last update was back in 2009. That's more than 3 years ago. I think that project has stalled. There must be something newer that has replaced it since then.

-- Dante



On Wed, Aug 22, 2012 at 6:26 AM, D. Dante Lorenso <da...@lorenso.com
<mailto:da...@lorenso.com>> wrote:

    All,

    I need to set up a server to enable 5,000 students to have web
    hosting provided by the school with PHP and MySQL support.  I'm
    trying to figure out what is the best way to do this.

    We have Active Directory and are using Centrify to authenticate
    usernames and passwords on our Linux servers.  I am imagining it
    would be great if we use something like ExecCGI to ensure that PHP
    runs as the user that owns the files.  We would then provide FTP
    access to the files and FTP would authenticate against Active
    Directory making sure to set the proper user/group on files when
    uploaded.

    I see that PHP-FPM exists: http://php-fpm.org  and it claims
    "Ability to start workers with different uid/gid/chroot/environment
    and different php.ini (replaces safe_mode)" which is exactly what
    I'm looking for.  It also claims "PHP-FPM is now included in PHP
    core as of PHP 5.3.3." so that's good.

    I also read about the greatness that is NGinX: http://nginx.org
    though I don't know if I can use it because I think I also need to
    use .htaccess files.  I need a way for students to be able to
    password protect their directories and files.  If there's another
    way using NGinX or Apache, that's good too.  I know of no other way.

    Here is an interesting article from 2009:
    
http://www.howtoforge.com/how-__to-set-up-mass-virtualhosting-__with-apache2-mod_rewrite-mod___userdir-mod_suexec-on-centos-__5.3
    
<http://www.howtoforge.com/how-to-set-up-mass-virtualhosting-with-apache2-mod_rewrite-mod_userdir-mod_suexec-on-centos-5.3>

    That uses mod_rewrite to attempt something like what I'm trying to
    do ... and then, Apache has mod_vhost_alias:
    http://httpd.apache.org/docs/__2.2/mod/mod_vhost_alias.html
    <http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html>

    So, I see a lot of information out there.  Apache, NginX, ExecCGI,
    FastCGI, mod_vhost_alias, mod_rewrite, SuExec, mod_userdir.  I
    suspect some of these methods are old and out of date.

    In my ideal situation:

      - users would be created in AD and would exist on the OS

      - student domain names would look like:
             http://<username>.student.__school.edu/
    <http://student.school.edu/> - OR -
    http://student.school.edu/<__username>/

      - file directories would look like:
             /mnt/somedir/<username>/__docroot

      - students would be able to create PHP applications executed with
             their own permissions

      - I would be able to configure all 5,000 accounts with a single
             configuration (1 virtual host rule?)

    Do you know what the "best practices" are for now ... here in 2012?

    -- Dante


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




--
Duken Marga



-- Dante

D. Dante Lorenso


--- End Message ---
--- Begin Message ---
On Sat, Aug 25, 2012 at 1:54 AM, Sebastian Krebs <krebs....@gmail.com> wrote:
> Am 25.08.2012 01:41, schrieb Fred Silsbee:
>
>> Warning:  Unknown: failed to open stream: Permission denied in Unknown on
>> line 0
>>
>>
>>
>> Fatal error:  Unknown: Failed opening required
>> '/var/www/html/log_book_MySQL.php'
>> (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0
>>
>> had to use Fedora yumex(yum) to install php
>>
>> PHP Version 5.4.5 is seen in phpinfo
>> before now,  php was there and ready after Fedora install
>>
>>
>
> Hi,
>
> I guess you created the file yourself (with your user account) and want to
> watch it within your browser via your webserver? The last one usually runs
> under the "www-data:www-data" (debian. Guess Fedora takes it similar)
> user:group. So, either change the owner, or change the permissions.
>
> An example
>
> | chmod g+rw /var/www/html/log_book_MySQL.php
> | chown www-data:www-data /var/www/html/log_book_MySQL.php
>
> and add yourself to the group www-data. Don't know, how it can be done in
> Fedora. Debian uses usermod, but as far as I know it's a debian tool(?).
>
> Regards,
> Sebastian
>

I don't use Fedora, but I doubt that would be necessary. All files
created by a user account have read rights for world, atleast on all
the Unix servers/PCs I maintain.
Maybe it's just a typo? Linux is case sensitive, so make sure the file
is really called log_book_MySQL.php, and not log_book_MYSQL.php for
example..

- Matijn

--- End Message ---
--- Begin Message ---
Am 25.08.2012 13:04, schrieb Matijn Woudt:
On Sat, Aug 25, 2012 at 1:54 AM, Sebastian Krebs <krebs....@gmail.com> wrote:
Am 25.08.2012 01:41, schrieb Fred Silsbee:

Warning:  Unknown: failed to open stream: Permission denied in Unknown on
line 0



Fatal error:  Unknown: Failed opening required
'/var/www/html/log_book_MySQL.php'
(include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0

had to use Fedora yumex(yum) to install php

PHP Version 5.4.5 is seen in phpinfo
before now,  php was there and ready after Fedora install



Hi,

I guess you created the file yourself (with your user account) and want to
watch it within your browser via your webserver? The last one usually runs
under the "www-data:www-data" (debian. Guess Fedora takes it similar)
user:group. So, either change the owner, or change the permissions.

An example

| chmod g+rw /var/www/html/log_book_MySQL.php
| chown www-data:www-data /var/www/html/log_book_MySQL.php

and add yourself to the group www-data. Don't know, how it can be done in
Fedora. Debian uses usermod, but as far as I know it's a debian tool(?).

Regards,
Sebastian


I don't use Fedora, but I doubt that would be necessary. All files
created by a user account have read rights for world, atleast on all
the Unix servers/PCs I maintain.

This depends on the umask. One may come to the conclusion to secure a system by setting a more restrictive umask (which is at all not that bad idea) and then some days/weeks/months later he realizes, that something stoped working. Changing the umask is useful, if you have many different users and you want them to be more separated from each others.

Maybe it's just a typo? Linux is case sensitive, so make sure the file
is really called log_book_MySQL.php, and not log_book_MYSQL.php for
example..

Good point too :D


- Matijn



--- End Message ---
--- Begin Message --- I know the response that I will get on the internals list, so I'll put this one past readers here ...

I've just switched to overhauling a commerce package extension to the framework that I'm upgrading to be E_STRICT complaint, and I've hit a little snag. The original designers took the approach of doing the language translations as define() constants with your just selecting the language to load. The problem comes with the fact that they load a generic file, and then follow it by additional defines for more accurate text ... overloading the generic copy ...

What I was not expecting was a string of 'Notices:' complaining about the redefines. So how does one get around this message? One can't 'if defined' as the string needs to be replaced with the more appropriate one. I would say, why is this even a problem, or alternatively I just give up on E_STRICT and make sure it's disabled again on PHP5.4?

Having spent several months getting the code clean on E_STRICT, switching it off again will really pig me off, but I can't see any real alternative given the number of languages and strings that will need reworking simply to get things clean :(

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk


--- End Message ---
--- Begin Message ---
On Sat, Aug 25, 2012 at 2:27 PM, Lester Caine <les...@lsces.co.uk> wrote:
> What I was not expecting was a string of 'Notices:' complaining about the
> redefines. So how does one get around this message? One can't 'if defined'
> as the string needs to be replaced with the more appropriate one. I would
> say, why is this even a problem, or alternatively I just give up on E_STRICT
> and make sure it's disabled again on PHP5.4?
>
> Having spent several months getting the code clean on E_STRICT, switching it
> off again will really pig me off, but I can't see any real alternative given
> the number of languages and strings that will need reworking simply to get
> things clean :(

Well, I'd do the following to avoid issues in the future.

1) Create a function like that below, which provides global access to
variables and allows you to update existing values:

        function val($name, $value = null)
        {
                static $values = array();

                if ($value === null) {
                        return isset($values[$name]) ? $values[$name] : null;
                } else {
                        return $values[$name];
                }
         }

2) Create a php script that searches out define("SOME_NAME_PATTERN",
"value") and replaces that with val("some_name_pattern", "value").

3) Create a php script that searches out SOME_NAME_PATTERN and
replaces with val("SOME_NAME_PATTERN");

Not too bad in terms of work, as PHP's parsing capabilities are really nice.

Hope this gives you ideas :)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
Op 25 aug. 2012 21:03 schreef "Adam Richardson" <simples...@gmail.com> het
volgende:
>
> On Sat, Aug 25, 2012 at 2:27 PM, Lester Caine <les...@lsces.co.uk> wrote:
> > What I was not expecting was a string of 'Notices:' complaining about
the
> > redefines. So how does one get around this message? One can't 'if
defined'
> > as the string needs to be replaced with the more appropriate one. I
would
> > say, why is this even a problem, or alternatively I just give up on
E_STRICT
> > and make sure it's disabled again on PHP5.4?
> >
> > Having spent several months getting the code clean on E_STRICT,
switching it
> > off again will really pig me off, but I can't see any real alternative
given
> > the number of languages and strings that will need reworking simply to
get
> > things clean :(
>
> Well, I'd do the following to avoid issues in the future.
>
> 1) Create a function like that below, which provides global access to
> variables and allows you to update existing values:
>
>         function val($name, $value = null)
>         {
>                 static $values = array();
>
>                 if ($value === null) {
>                         return isset($values[$name]) ? $values[$name] :
null;
>                 } else {
>                         return $values[$name];
>                 }
>          }
>
> 2) Create a php script that searches out define("SOME_NAME_PATTERN",
> "value") and replaces that with val("some_name_pattern", "value").
>
> 3) Create a php script that searches out SOME_NAME_PATTERN and
> replaces with val("SOME_NAME_PATTERN");
>
> Not too bad in terms of work, as PHP's parsing capabilities are really
nice.
>
> Hope this gives you ideas :)
>
> Adam
>

That's probably quite some work given the many defines.. Fact is, constants
are, as the name says, constant. Would it be possible to just not include
the general file?
Second, though not 100% sure if it works for E_STRICT is using @ before all
defines to silence the warning. You could do a simple replace for that..

- Matijn

--- End Message ---
--- Begin Message ---
Can you just switch the order?

Instead of...

   define("SOME_CONSTANT","Generic Value");
   define("SOME_CONSTANT","Override Value");

Why not do...

   define("SOME_CONSTANT","Override Value");
   if(!defined("SOME_CONSTANT")) { define("SOME_CONSTANT","Generic Value"); }

This should avoid any redefinition and thus the notices.

Matt

On Sat, Aug 25, 2012 at 3:07 PM, Matijn Woudt <tijn...@gmail.com> wrote:
> Op 25 aug. 2012 21:03 schreef "Adam Richardson" <simples...@gmail.com> het
> volgende:
>>
>> On Sat, Aug 25, 2012 at 2:27 PM, Lester Caine <les...@lsces.co.uk> wrote:
>> > What I was not expecting was a string of 'Notices:' complaining about
> the
>> > redefines. So how does one get around this message? One can't 'if
> defined'
>> > as the string needs to be replaced with the more appropriate one. I
> would
>> > say, why is this even a problem, or alternatively I just give up on
> E_STRICT
>> > and make sure it's disabled again on PHP5.4?
>> >
>> > Having spent several months getting the code clean on E_STRICT,
> switching it
>> > off again will really pig me off, but I can't see any real alternative
> given
>> > the number of languages and strings that will need reworking simply to
> get
>> > things clean :(
>>
>> Well, I'd do the following to avoid issues in the future.
>>
>> 1) Create a function like that below, which provides global access to
>> variables and allows you to update existing values:
>>
>>         function val($name, $value = null)
>>         {
>>                 static $values = array();
>>
>>                 if ($value === null) {
>>                         return isset($values[$name]) ? $values[$name] :
> null;
>>                 } else {
>>                         return $values[$name];
>>                 }
>>          }
>>
>> 2) Create a php script that searches out define("SOME_NAME_PATTERN",
>> "value") and replaces that with val("some_name_pattern", "value").
>>
>> 3) Create a php script that searches out SOME_NAME_PATTERN and
>> replaces with val("SOME_NAME_PATTERN");
>>
>> Not too bad in terms of work, as PHP's parsing capabilities are really
> nice.
>>
>> Hope this gives you ideas :)
>>
>> Adam
>>
>
> That's probably quite some work given the many defines.. Fact is, constants
> are, as the name says, constant. Would it be possible to just not include
> the general file?
> Second, though not 100% sure if it works for E_STRICT is using @ before all
> defines to silence the warning. You could do a simple replace for that..
>
> - Matijn

--- End Message ---
--- Begin Message ---
On Sat, 2012-08-25 at 15:17 -0400, Matt Neimeyer wrote:

> Can you just switch the order?
> 
> Instead of...
> 
>    define("SOME_CONSTANT","Generic Value");
>    define("SOME_CONSTANT","Override Value");
> 
> Why not do...
> 
>    define("SOME_CONSTANT","Override Value");
>    if(!defined("SOME_CONSTANT")) { define("SOME_CONSTANT","Generic Value"); }
> 
> This should avoid any redefinition and thus the notices.
> 
> Matt
> 
> On Sat, Aug 25, 2012 at 3:07 PM, Matijn Woudt <tijn...@gmail.com> wrote:
> > Op 25 aug. 2012 21:03 schreef "Adam Richardson" <simples...@gmail.com> het
> > volgende:
> >>
> >> On Sat, Aug 25, 2012 at 2:27 PM, Lester Caine <les...@lsces.co.uk> wrote:
> >> > What I was not expecting was a string of 'Notices:' complaining about
> > the
> >> > redefines. So how does one get around this message? One can't 'if
> > defined'
> >> > as the string needs to be replaced with the more appropriate one. I
> > would
> >> > say, why is this even a problem, or alternatively I just give up on
> > E_STRICT
> >> > and make sure it's disabled again on PHP5.4?
> >> >
> >> > Having spent several months getting the code clean on E_STRICT,
> > switching it
> >> > off again will really pig me off, but I can't see any real alternative
> > given
> >> > the number of languages and strings that will need reworking simply to
> > get
> >> > things clean :(
> >>
> >> Well, I'd do the following to avoid issues in the future.
> >>
> >> 1) Create a function like that below, which provides global access to
> >> variables and allows you to update existing values:
> >>
> >>         function val($name, $value = null)
> >>         {
> >>                 static $values = array();
> >>
> >>                 if ($value === null) {
> >>                         return isset($values[$name]) ? $values[$name] :
> > null;
> >>                 } else {
> >>                         return $values[$name];
> >>                 }
> >>          }
> >>
> >> 2) Create a php script that searches out define("SOME_NAME_PATTERN",
> >> "value") and replaces that with val("some_name_pattern", "value").
> >>
> >> 3) Create a php script that searches out SOME_NAME_PATTERN and
> >> replaces with val("SOME_NAME_PATTERN");
> >>
> >> Not too bad in terms of work, as PHP's parsing capabilities are really
> > nice.
> >>
> >> Hope this gives you ideas :)
> >>
> >> Adam
> >>
> >
> > That's probably quite some work given the many defines.. Fact is, constants
> > are, as the name says, constant. Would it be possible to just not include
> > the general file?
> > Second, though not 100% sure if it works for E_STRICT is using @ before all
> > defines to silence the warning. You could do a simple replace for that..
> >
> > - Matijn
> 


I think the point is that the code is relying on overriding the
constants, so that wouldn't help at all. I think the best thing would be
to re-write the code, constants are never meant to be treated like that,
it's entirely the opposite of what a constant is.
-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote:
I think the point is that the code is relying on overriding the
constants, so that wouldn't help at all. I think the best thing would be
to re-write the code, constants are never meant to be treated like that,
it's entirely the opposite of what a constant is.

I've 45 languages and several hundred strings per language ;)
Redefining 'define' as a new function is looking the easiest option as I can just replace all the defines in the language files. Then simply run a clean set of defines as I can't easily replace all of that text in the rest of the code tree :(

I can see why the approach was taken originally as it READS a lot better than building the translations as an array of strings which is used in other packages. There are only some 800 strings to be reworked later ... across a few hundred files ...

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk



--- End Message ---

Reply via email to