The legions that fought the phallanx were exactly up to par either to be fair, it was decades after the Second Punic War and the organization, dicipline and skill had dropped significantly, however the phallangites were far from their best organization. First, cavalry was placed inbteween cohorts(or whatever you call them in a phallanx army) and there was almost nothing as a proper flank. Had it been Alex's army, that would have probably never happened as he wuld have a strong and formidable cavalry force in the flanks that would counter any encirclement attempt along with skirmishers who would give the legions hell. However.... This is just an assumption....
Yes...the situation and pairing I speak of is more hypothetical for over-all efficiency than any actual battles that occurred. Something along the lines of a Macedonian phalanx vs. Caesarian cohort.
Another thing to consider is the fact that Greek and Macedonian phalanxes seemed to be different in terms of the size of the pike used, the Macedonian one being quite long.
Despite it all, the heavily armed yet more maneuverable legionnaire can just push his way past the pike points to use his deadly gladius up close where the phalanx soldier was compromised and at a disadvantage even if he dropped his pike and went for his sword.