Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
Indeed it seems PHP is the new COBOL. In that it's a language that the ancients used and is largely forgotten except for a daring few who will take on maintenance.

COBOL programmers make serious bank these days.

Adbot
ADBOT LOVES YOU

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Tad Naff posted:

Question: when did kids stop learning PHP? It used to be that was the one web language we could count on applicants to at least have run across, which is why we standardized on it.

When node came out. Once people only had to learn/teach one language to do both frontend and backend, that's what everyone switched to.

FAT32 SHAMER
Aug 16, 2012



Yeah node is the new hotness

Er I guess technically ember since that's what all the webdev people who graduated below me like

RedQueen
Apr 21, 2007

It takes all the running you can do just to stay in the same place.
Does anyone use VS Code for PHP? I tried it with the most popular extensions (a few different php IntelliSense extensions). Most of the advertised features worked nicely but I couldn't get good autocomplete suggestions for built-in php functions with any of the setups. Trying to type var to get a var_dump() suggestion only worked with the default Microsoft setting, these extensions (which tell you to disable "php.suggest.basic" and let the extensions take over) would not suggest it at all. That made VS code seem inferior to my Sublime setup.

FAT32 SHAMER
Aug 16, 2012



I use phpstorm when I have to touch php, which has been twice so far in six months

Doh004
Apr 22, 2007

Mmmmm Donuts...

duz posted:

When node came out. Once people only had to learn/teach one language to do both frontend and backend, that's what everyone switched to.

I dunno, I'm pretty sure PHP started dying as Rails and/or Django started their relevance about 7 years ago. No doubt JS (Node) is the current hotness and has basically taken up what new programmers learn nowadays.

DICTATOR OF FUNK
Nov 6, 2007

aaaaaw yeeeeeah

RedQueen posted:

Does anyone use VS Code for PHP? I tried it with the most popular extensions (a few different php IntelliSense extensions). Most of the advertised features worked nicely but I couldn't get good autocomplete suggestions for built-in php functions with any of the setups. Trying to type var to get a var_dump() suggestion only worked with the default Microsoft setting, these extensions (which tell you to disable "php.suggest.basic" and let the extensions take over) would not suggest it at all. That made VS code seem inferior to my Sublime setup.

Seconding PhpStorm. It will make things far more tolerable.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
Microsoft has also removed a lot of barriers to getting up and running with C# and that sweet, sweet type safety is a huge plus over PHP. PHP just doesn't have anything unique to offer people anymore. It feels super inelegant.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I say the above as someone who personally has a real soft spot for PHP.

bigmandan
Sep 11, 2001

lol internet
College Slice
If it was not for all the legacy applications and large number of internal libraries we've written, we'd probably switch to C# where I'm at.

itskage
Aug 26, 2003


Cross posting this from the general thread:

I'm really enjoying eslint. When we started a node.js project I was able to configure very specific rules for it, pass them to my team, and then enforce them by making our CI run the linter and fail any commits that don't pass. It's a nice extra layer of tidyness and some safety in the javascript world, without going to something like typescript.

Is there anything as robust and customizable for PHP? I'd love to run some of the PHP stuff we still maintain through something like this, but I can't find anything that lets you be quite as specific in the settings, or also played nice with IDEs and CIs.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
You might be looking for PHP Mess Detector and PHP_CodeSniffer.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I haven't done any PHP for ages. Recently updated from php5 to php7 and I'm having trouble with a "class not found" error in some old code. I have my autoloader defined as:
code:
	function __autoload($class_name) {
		$filename = strtolower($class_name) . '.php';
		$file = ROOTPATH."private/model/".$filename;
		if (file_exists($file) == false) {
			return false;
		}
		include ($file);
	}
It seems to be able to find some classes just fine, but it doesn't seem to even by attempting to call my autoload function in this case:
code:
Fatal error: Uncaught Error: Class 'UserUtils' not found

McGlockenshire
Dec 16, 2005

GOLLOCKS!
__autoload has been deprecated in the next release. You should be using spl_autoload_register instead, and should have been for literally over ten years.

You should be able to sniff out the problem with a little more verbosity and a switch from include to require_once so that a failure there is more immediate and obvious. Needless to say, you should already have your error_reporting cranked all the way up to E_ALL.

PHP code:
	spl_autoload_register(function ($class_name) {
		$filename = strtolower($class_name) . '.php';
		$file = ROOTPATH."private/model/".$filename;
		if (file_exists($file) == false) {
			trigger_error(sprintf('Could not locate file "%s" for class "%s"', $file, $class_name), E_USER_WARNING);
			debug_print_backtrace();
			return false;
		}
		require_once ($file);
	});
You should also consider adapting the basic PSR-4 autoloader because your autoloader will break horribly the instant that you invoke something with a namespace.

McGlockenshire fucked around with this message at 07:06 on Sep 10, 2017

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

McGlockenshire posted:

__autoload has been deprecated in the next release. You should be using spl_autoload_register instead, and should have been for literally over ten years.

You should be able to sniff out the problem with a little more verbosity and a switch from include to require_once so that a failure there is more immediate and obvious. Needless to say, you should already have your error_reporting cranked all the way up to E_ALL.

PHP code:
	spl_autoload_register(function ($class_name) {
		$filename = strtolower($class_name) . '.php';
		$file = ROOTPATH."private/model/".$filename;
		if (file_exists($file) == false) {
			trigger_error(sprintf('Could not locate file "%s" for class "%s"', $file, $class_name), E_USER_WARNING);
			debug_print_backtrace();
			return false;
		}
		require_once ($file);
	});
You should also consider adapting the basic PSR-4 autoloader because your autoloader will break horribly the instant that you invoke something with a namespace.

Thank you for the very thorough answer! I dropped your snippet in place of mine and it seems to be working now.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
I'm glad it's working, but I changed none of the code that actually mattered from your original.

If you haven't already performed an appropriate animal sacrifice to the PHP gods, I suggest appeasing them now. Your code is haunted.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

McGlockenshire posted:

I'm glad it's working, but I changed none of the code that actually mattered from your original.

If you haven't already performed an appropriate animal sacrifice to the PHP gods, I suggest appeasing them now. Your code is haunted.

Haha that's what it seemed like! I have no idea what the deal was. This is for Awful Yearbook, so it is most certainly haunted.

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

fletcher posted:

Haha that's what it seemed like! I have no idea what the deal was. This is for Awful Yearbook, so it is most certainly haunted.

That thing still exists? Huh.

BallerBallerDillz
Jun 11, 2009

Cock, Rules, Everything, Around, Me
Scratchmo
I'm not sure if this should really go here since it might be more of an AWS question, but I don't see an AWS/:yayclod: thread so maybe one of you fine folks have an answer for me.

My AWS forum post posted:

I'm attempting to pull a custom metric from the Cloudwatch API via PHP and haven't been able to get it working properly. I can pull standard metrics just fine, so it's not an issue with improperly configured IAM roles or anything. I think maybe the actual statistic I'm requesting is wrong but I think I've tried it with every statistic option available. I'm trying to get the custom DiskSpaceUtilization metric in the System/Linux namespace. I have the Cloudwatch perl scripts installed on my instance and they're reporting disk statistics every 5 minutes via a cron job that I can see just fine via the Cloudwatch GUI. Requesting the custom metric via the API doesn't give me an error, it just return an empty Datapoints array.

I've attached copies of both working code for a generic metric along with the non-working code for the custom metric. I'm still learning PHP so I may just be making an obvious error, but I'd appreciate it if someone can take a look at it and see if that's the case. If it's just not possible that would be good to know too. Thank you very much.

This one works
php:
<?php
require $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
use Aws\CloudWatch\CloudWatchClient;
use Aws\Exception\AwsException;


$client = new CloudWatchClient([
    'region' => 'us-west-2',
    'version' => 'latest'
]);

try {
    $result $client->getMetricStatistics(array(
      'Namespace' => 'AWS/EC2',
      'MetricName' => 'NetworkPacketsOut',
      'Dimensions' => array(
          array(
            'Name' => 'InstanceId',
            'Value' => 'i-093348c63a21c8068'
          ),
        ),
      'StartTime' => strtotime('-6 hours'),
      'EndTime' => strtotime('now'),
      'Period' => 60,
      'Statistics' => array('Average'),
    ));
    echo '<pre>';
    var_dump($result);
    echo '</pre>';
} catch (AwsException $e) {
    error_log($e->getMessage());
}

?>

This one doesn't
php:
<?php
require $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
use Aws\CloudWatch\CloudWatchClient;
use Aws\Exception\AwsException;


$client = new CloudWatchClient([
    'region' => 'us-west-2',
    'version' => 'latest'
]);

try {
    $result $client->getMetricStatistics(array(
      'Namespace' => 'System/Linux',
      'MetricName' => 'DiskSpaceUtilization',
      'Dimensions' => array(
          array(
            'Name' => 'InstanceId',
            'Value' => 'i-093348c63a21c8068'
          ),
          array(
            'Name' => 'MounthPath',
            'Value' => '/'
          ),
          array(
            'Name' => 'Filesystem',
            'Value' => '/dev/xda1/'
          ),
      ),
      'StartTime' => strtotime('-6 hours'),
      'EndTime' => strtotime('now'),
      'Period' => 60,
      'Statistics' => array('Maximum''Minimum''Average''Sum''SampleCount'),
    ));
    echo '<pre>';
    var_dump($result);
    echo '</pre>';
} catch (AwsException $e) {
    error_log($e->getMessage());
}

?>

Shy
Mar 20, 2010

MounthPath instead of MountPath?

BallerBallerDillz
Jun 11, 2009

Cock, Rules, Everything, Around, Me
Scratchmo
:smithicide:

Well thank you for pointing that out, I'm a dummy, but unfortunately fixing it didn't actually fix the issue (and I'm actually pretty sure I had tried it the right way at some point but screwed it up when I was copy/pasting things in and out of that dimensions array). I may just move on to something else, building a bespoke AWS dashboard seemed like a fun way to learn php but I'm not doing anything that isn't already done much better by the Cloudwatch dashboard anyway. I learned how to install/use the AWS PHP SDK, maybe I should just build a page that will let me provision/destroy hosts from a single page.

Thanks for taking a look at it.

Murrah
Mar 22, 2015

Ok. All ears for any tips on where to start on something. Im ready to do my own work but just lacking any kind of direction to go in right now.

Ive been assigned a ticket at work that basically was framed as follows: Estimate the number of hardcoded strings in the app. This is for the purpose of getting some kind of estimates for how much work will be involved i18n-wise to internationalizing the app/ translate it.

The thing is, its a PHP Symfony 1.x based project where there are strings all over all place in HTML and Echo'd from PHP and put in place by JavaScript. Its not a straightforward thing.

Ive explained this to the project lead that the idea of hard-coded string is a bit misleading/not applicable but the response was basically "thanks for your research- go with what you can to get the best estimate possible".


So throwing a pebble out there and wondering if anyone has had any experience doing this kind of thing on a relatively legacy PHP project

McGlockenshire
Dec 16, 2005

GOLLOCKS!
What is their definition of a "hardcoded string"?

Why is this being asked for?

Murrah
Mar 22, 2015

McGlockenshire posted:

What is their definition of a "hardcoded string"?

Why is this being asked for?

e: There is no definition given.

Its for the purpose of estimating how much content is user facing that will need to be translated. In some apps like Java I imagine there is a clear distinction between whats a hardcoded string or not, so you could do some stuff with an IDE or commands to estimate how many such strings exist.

Im guessing that my boss has read some stuff about getting translation work done and it said the first step is to estimate the strings in the app somewhere.

I think I am going to have to pushback and explain again that what I am being asked A) isn't clear b) Is very hard to do with how unclear it is

Murrah fucked around with this message at 01:02 on Oct 30, 2017

McGlockenshire
Dec 16, 2005

GOLLOCKS!
Yeah, unless the application was built under the assumption that it'd need to be translated later, there's going to be no really easy way to get an estimate anywhere near close to reality without actually counting. Translatable strings could be anywhere throughout the entire structure of the application. Don't forget about error messages, etc.

You could probably fake it by processing the output of each page through a browser. Every non-empty text node in the DOM is likely to be at least one string appearing somewhere in the source. That might give you a reasonable lower bounds.

I'd be very careful with the number. As you've already guessed, this might be for some external contractor to get a copy of the source and mangle it based on the estimate that you provide, meaning a bad estimate could result in them wanting more money later, etc.

McGlockenshire fucked around with this message at 02:07 on Oct 30, 2017

FAT32 SHAMER
Aug 16, 2012



I would overestimate rather than underestimate, just to be sure

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Wouldn't a regex count pass through all the files at least give an idea?

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Yeah, if they just want a rough estimate then do a grep for ' = "' or something. Then add a large number to represent the strings in the HTML files.

ConanThe3rd
Mar 27, 2009
So, I have a client who wants to take their Excell spreadsheet of ID Numbers and copy-paste it into a textfield to apply a status to it.

Currently I have explode() doing that but I'm not sure what character I use for a new row for excell, any help?

kiwid
Sep 30, 2013

ConanThe3rd posted:

So, I have a client who wants to take their Excell spreadsheet of ID Numbers and copy-paste it into a textfield to apply a status to it.

Currently I have explode() doing that but I'm not sure what character I use for a new row for excell, any help?

Can you get the format in CSV instead?

ConanThe3rd
Mar 27, 2009

kiwid posted:

Can you get the format in CSV instead?

:/ I was affraid that was the answer.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.

ConanThe3rd posted:

So, I have a client who wants to take their Excell spreadsheet of ID Numbers and copy-paste it into a textfield to apply a status to it.

Currently I have explode() doing that but I'm not sure what character I use for a new row for excell, any help?

If you can have them upload the file rather than copying and pasting the data, you can use https://packagist.org/packages/phpoffice/phpexcel to process it.

nielsm
Jun 1, 2009



ConanThe3rd posted:

So, I have a client who wants to take their Excell spreadsheet of ID Numbers and copy-paste it into a textfield to apply a status to it.

Currently I have explode() doing that but I'm not sure what character I use for a new row for excell, any help?

If you implement a rich-text editor (i.e. a contentEditable HTML thing), copy-paste from Excel will usually end up as an actual HTML table you can traverse client side with DOM, or submit and parse as HTML.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
If they're ID numbers could you not just regex them?

Murrah
Mar 22, 2015

E: NVM, forgot there is an entire wordpress thread

Murrah fucked around with this message at 05:00 on Nov 17, 2017

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
Does anyone have any recommendations for beginner PHP tutorials for creating REST APIs?

teen phone cutie fucked around with this message at 19:24 on Dec 7, 2017

jiggerypokery
Feb 1, 2012

...But I could hardly wait six months with a red hot jape like that under me belt.

I would just play about with a framework's documentation, rather than working through any tutorial.

https://silex.symfony.com/

Silex is a good choice because it doesn't hide tooooooo much from you under a layer of magic but you can get a lot done quickly with it (I am a symfony fanboy, silex's big brother).

Programming is all about abstraction of course so you should be able to read a blog post or book or what ever on REST that's language agnostic and apply the RESTful pattern to the silex routing component.

Likewise, you could pick any different framework and do the same thing.

Switch in whatever framework you like, they all have routing components. I wouldn't bother writing your own routing component though, plenty of people would recommend that you do, however.

-JS-
Jun 1, 2004

Personally I wouldn't go for Silex right now as it's been end-of-life'd. Slim or Lumen maybe instead? Depends what your starting point is.

teen phone cutie
Jun 18, 2012

last year i rewrote something awful from scratch because i hate myself
Well i guess the reason I want to learn REST practices in PHP is mostly because we use PHP at work on our apps.

And i’ve been making my best attempt to be more of a full stack developer, as I’ve pretty much been doing frontend through my career.

But I’ll be sure to read through the docs of these frameworks and see what i like!

Adbot
ADBOT LOVES YOU

jiggerypokery
Feb 1, 2012

...But I could hardly wait six months with a red hot jape like that under me belt.

Ah yeah, I guess the plan is for Symfony flex to take over Silex. Lumen might be a good choice for the same reason as Silex. You can use it as a stepping stone into the big brother framework (Laravel) without having too much of whats going on hidden from you.

It really doesn't matter what framework you use, as long as you learn it well. What do your backend developers use?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply